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!

ways to parse a XML file to generate a cursor?

Status
Not open for further replies.

opticalman

Programmer
Nov 6, 2006
103
US
I am new to XML
I am using VFP8.
I am looking into sending orders to a vendor via XML.
My vendor has supplied me a sample of an XML file that he receives from other customers.

I can successfully generate a XML file from a local cursor via the CURSORTOXML() function. I can then regenerate a cursor from the created XML file via the XMLTOCURSOR() function. My problem is when I try to generate a cursor from the sample XML file from my vendor. Using the same XMLTOCURSOR() function yields a cursor/table with less that half of the expected columns and no data in the fields.

I have also tried the XMLadapter via the command box, by entering the commands suggested in VFP help, but I receive an error.

Code:
oXMLAdapter = NEWOBJECT('XMLAdapter')
cFile = GETFILE()          && select sample XML
cXml = FILETOSTR( cFile )  && load to string
MESSAGEBOX( oXMLadapter.LoadXML(cXML) ) 
             && load is confirmed by  .T.  
MESSAGEBOX(;
  oXMLAdapter.Tables.Item(1).Fields.Item(1).DataType )
&&(Error 2061)  Index or expression does not 
&& match an  existing member of the collection.
My question is: are there other ways to parse a XML files to generate a cursor?

Jim Rumbaugh
 
Just parse it. It requires a little work. e.g. thread1251-1308996


Brian
 
Brian

Thanks for reference. I get the idea, and I like the code you wrote in the example. Perhaps I was too naïve for thinking there would be a one-size fits all conversion utility.

Jim Rumbaugh
 
I wish there was. Makes one think a delimited text file with headers and <table> </table> tags might not only be smaller and more efficient, but easier to use in many situations too [surprise]

 
I've been working with a lot of XML lately and have found using MSXML as a parser and XML Notepad (free download from MS) to be very useful. XML Notepad makes the file easier to understand so that when you start playing with manipulating the nodes in MSXML you have a bit more success. I believe that most of the parsing functionality (if not all) of MSXML is in VFP's XMLadapter but since I'm not converting the XML into cursors I found MSXML a little easier to work with, particularly when using the MS documentation (Platform SDK)

If you use MSXML you may find the SelectNodes and SelectSingleNode search methods useful. I do find the Xpath argument to those methods a bit confusing but I'm certain that's because of my unfamiliarity with XML. Fortunately for my uses I have found samples and trial and error me what I needed.

Ralph Kolva

 
I thought I would add that I have posted a tip on how to take an html data table and populate a cursor. It was intersting to do and might be helpful to someone investigating this thread.

HTML TABLE TO CURSOR THREAD: thread1253-1377858

Regards,

Rob
 
Rob

I LOVE IT!!. Now I that I see how to extract data from a I.E. screen, I now want to know how to programtacilly fill in an I. E. screen. But maybe that should be another thread.

Jim Rumbaugh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top