Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP + XML, DOMDocument & Multiple Processing Inst.

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
US
My success with VFP9's XMLAdapter has been non-existent.

My client supplied XML file appears to be too complex to handle it since it always generates an error message when I execute:
Code:
oXMLAdapter = NEWOBJECT('XMLAdapter')
mcXMLDoc = GETFILE("XML")
oXMLadapter.LoadXML(mcXMLDoc)

  [B]XML Error: XML Parse Error: Invalid at top 
     level of document <filename>[/B]

Consequently I have reverted to using the DOMDocument approach.

And I have managed to navigate myself through simple XML documents finding 'fields' and 'values' by drilling down into the various element layers. So far so good.

But now when I examine my client's XML document via Notepad, I find that the single XML document contains multiple Processing Instruction lines
<?xml version="1.0" encoding="UTF-8"?>
and the following associated elements.

When attempting to use the DOMDocument approach I can execute the following code without generating any errors:
Code:
oXML = CREATEOBJECT('msxml2.DOMDocument.4.0')
mcXMLDoc = GETFILE("XML")
oXML.LOAD(mcXMLDoc)

In the more simple XML documents I know what to do and how to handle the various Nodes, etc.

But in this more complex XML document I have no idea how to cycle through the various 'sub-documents' (my term for each piece following the unique <?xml version="1.0" encoding="UTF-8"?> strings).

Is someone out there familiar enough with using VFP with the XML DOMDocument to advise me how to sequentially step through the individual sub-docs 1, 2, 3, etc.

When I look for web references I only find simplistic XML doc examples - they don't tell me anything that I can't already handle.
But I have yet to find any web references to which DOM Objects to use to parse this complex of an example.

Any advice/suggestions you might have would be greatly appreciated.

OR, my first choice, if you can advise me as to how to utilize the VFP9 XMLAdapter or XMLtoCursor to parse/convert an XML document of this complexity I would be most greatful.

Thanks,
JRB-Bldr
 
In case my explanation above was not clear, here is an abbreviated copy of the client-provided XML document

[Note]
<?xml version="1.0" encoding="UTF-8"?><A:VendorXML xmlns:A=" xmlns:xsi=" </A:IFSGroupCd></A:Scores><A:producerData><A:producerId>088832</A:producerId></A:producerData></A:VendorXML>
<?xml version="1.0" encoding="UTF-8"?><A:VendorXML xmlns:A=" xmlns:xsi=" </A:IFSGroupCd></A:Scores><A:producerData><A:producerId>075347</A:producerId></A:producerData></A:VendorXML>
<?xml version="1.0" encoding="UTF-8"?><A:VendorXML xmlns:A=" xmlns:xsi=" </A:IFSGroupCd></A:Scores><A:producerData><A:producerId>023820</A:producerId></A:producerData></A:VendorXML>
<?xml version="1.0" encoding="UTF-8"?><A:VendorXML xmlns:A=" xmlns:xsi=" </A:IFSGroupCd></A:Scores><A:producerData><A:producerId>075347</A:producerId></A:producerData></A:VendorXML>
<?xml version="1.0" encoding="UTF-8"?><A:VendorXML xmlns:A=" xmlns:xsi=" </A:IFSGroupCd></A:Scores><A:producerData><A:producerId>023820</A:producerId></A:producerData></A:VendorXML>
[/Note]

In reality it might go on in a similar manner for 5000 'records'.

As you can see I am presented with multiple Processing Instruction lines. (the <?xml version="1.0" encoding="UTF-8"?> lines)

I need to get the above data read into a single VFP cursor/table in order to do subsequent processing on it.

I can use the DOMDocument object approach to parse in the first 'record', but after than things fall apart.

I would like to utilize XML tools which are already available to me such as VFP9's XMLAdapter or M$ DOMDocument.

However I am having the difficulties stated above.

Any advice/suggestions that you might have on how to parse a file like presented here, I would greatly appreciate it.

Thanks,
JRB-Bldr
 
Am I correct in saying that they're sending several separate or individual XMLs in one submission? If so, have you tried using FILETOSTR() to get the entire file and then loop though it one XML at a time, handling each XML portion separately? This should avoid the problem with the XMLadapter object objecting to multiple initializations. (I hope.)

While ideally they should be sending the data differently, either building a correct combined XML or sending separate XMLs, the programmer usually is stuck with what he's sent.
 
In case I didn't say so before, I feel VFP support of XML structures is somewhat limited and reading or writing any complex XML will require some specific additional coding to get the layers correct. I've used XmlToCursor(), CursorToXml() and XmlAdapter object. By far, the XmlAdapter object is the best. Maybe part of the problem is how to convert a multi-level child XML into a simple 2-dimensional table or cursor. Round peg into a square hole situation.

For other comments I've made, see thread1253-1179650 or thread1253-1155506

dbMark
 
Thanks Mark for your reply.

I knew that the document contents looked strange.
Finally the client confirmed that they were not REALLY sending me an XML file.
Instead they are sending me a text file containing multiple XML documents. Specifically one XML document per data 'record'. What a mess.

When I asked them to send it in a more standard, one XML document with multiple data 'records', they merely said "No - deal with it."

I guess that it is no wonder that neither XMLAdapter nor DOMDocument work successfully.

Is there a file size limit to FILETOSTR()

If they send me 5000 to 10000 'records', that will be a pretty good sized file. Especially with all of the 'bloat' from the extra (and unnecessary??) XML nodes.

I appreciate your confirming what I thought.
And I appreciate any advice you might still have to offer.

Thanks,
JRB-Bldr
 
VFP 9.0 allows manipulation of strings up to 2 GBs in size. I'm not sure about earlier versions. It is limited by the amount of available memory or disk space.
 
I'll bet Alines(FileToStr(<filename>)) would pull the whole thing into an array (if you have enough memory) and then you could process each element as a separate XML document.

If you can get VendorXML.xsd and assign it as a schema, it seems like it would be rather simple to import that data into a VFP cursor using either XMLAdapter or XMLToCursor

pamela
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top