Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Paul Gibson
  Where is Paul Gibson?
 Glasgow
 United Kingdom
 Paul Gibson
 To: Paul Gibson
  Where is Paul Gibson?
 Glasgow
 United Kingdom
 Paul Gibson
 Tags
Subject: RE: Efficient XML Parsing
Thread ID: 372993 Message ID: 373264 # Views: 90 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: XML
Date: Wednesday, March 20, 2013 3:37:02 PM         
   


> What is the most efficient way people use for parsing XML in VFP to get the data into tables?
>
> ...

Hi Guys,

thanks you all very much for taking the time to help me work out the best way to go. I dismissed XMLToCursor() almost immediately, the XML I am trying to parse is too complex. I have done manual DOM parsing in the past and found that effective but would prefer something more efficient, pulling out tens of thousands of items from tags seems a laborious way to do it, the code wouldn't take too long to write and maybe I have to fall back on this option if I can't get anything else to work.

I have tried to test the limitations of the XMLAdapter class to see if that can do what I need to, I have something which I could almost work with but I think the main problem is that I am trying to parse XML which has a parent-child relationship in it where none of the data helps link the parent to the child or vice versa. There can be many parents and each parent may have an unknown number of children. Ideally I would want to parse the XML into two tables where there was some clear link between the parent and child tables and that is what I'm struggling with.

My other small niggle which I could traverse in an ugly way is that I have other "complex types" in the XML which all belong to the parent in a one-to-one relationship but they also get extracted as separate tables/cursors. I can easily join them based on the first row of one table being linked to the first row of all the other tables (except the child table) etc etc but that's ugly even if it is possible it's not a nice join.

I have read all the responses, I can't access the January issue of FoxRockx so I don't know what the suggestion in that article is and I haven't downloaded Rick's cpp program as I want to do this in pure VFP if I can. In Cetin's most recent post on this I don't think I fully understand yet what the custom XMLAdapterUtils class is used for and what advantage it gives. Further study required here I think.

I won't post the XML in this message because the formatting often messes things up but I will attach a program that uses the XML in an XMLAdapter class and attempts to parse the information. The XML in my program isn't the exact XML that I'm trying to parse, I've had to obfuscate it a little - just by changing the data and the names, the structure of the XML is identical to the real XML I am trying to import and that's the important thing. I wasn't given an XSD but I used an online tool to generate one that I could alter if required.

Here is what I have got so far:
https://www.foxite.com/uploads/1975dd48-3332-4eed-9eab-0ffa01dddec2.zip

The general structure of the data in the XML is as follows:

1) One or more parents: ref, id, date, time, source address (six properties as separate fields), destination address (another six properties), action information (3 properties)
2) Within each parent - one or more children: id, length, breadth, width, weight

Ideally I want to parse that XML and get two tables/cursors one containing all the parent information, one containing all the child information and a link between the two tables as there is no way using the data against the parent elements or child elements of linking the parent to the children other than in the XML the children are "within" the parents.

Not vitally important but slightly irritating during testing is that all my strings seem to default to Memo fields, I wonder if there is an easy way to sort that out.

I don't know if everything that I am looking for is possible using the XMLAdapter class. In my sample XML there are two parents and five children and in the resultant parent and child cursors I have no way or working out which children go against which parents. Even if I could merge the complex types parsing into the parent I'd need a way of sorting out the field names because both the source and destination have tags in them called addr1, addr2 etc but it's not my main concern because I can write (and have written) post-parsing code to sort those out if my only option is to parse them out into separate tables.

The XML is produced by someone else so I have no way of changing the way the XML is structured. I am not familiar enough with the XMLAdapter class to know if I'm missing anything simple or if there is any way at all of doing what I am trying to do without resorting to parsing the DOM.

Thanks very much for your time.

ENTIRE THREAD

Efficient XML Parsing Posted by Paul Gibson @ 3/15/2013 4:05:13 PM
RE: Efficient XML Parsing Posted by James Frye @ 3/15/2013 7:21:49 PM
RE: Efficient XML Parsing Posted by Marco Plaza @ 3/15/2013 7:44:46 PM
RE: Efficient XML Parsing Posted by Ulhas Amrite @ 3/31/2013 5:43:14 AM
RE: Efficient XML Parsing Posted by Marco Plaza @ 3/31/2013 5:08:50 PM
RE: Efficient XML Parsing Posted by Tamar Granor @ 3/15/2013 9:14:02 PM
RE: Efficient XML Parsing Posted by Rick Hodgin @ 3/15/2013 9:29:53 PM
RE: Efficient XML Parsing Posted by Rick Hodgin @ 3/15/2013 9:47:44 PM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/15/2013 11:38:43 PM
RE: Efficient XML Parsing Posted by Srdjan Djordjevic @ 3/19/2013 5:24:20 PM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/20/2013 12:47:51 PM
RE: Efficient XML Parsing Posted by Srdjan Djordjevic @ 5/14/2013 11:35:15 AM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/20/2013 12:52:49 PM
RE: Efficient XML Parsing Posted by Paul Gibson @ 3/20/2013 3:37:02 PM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/20/2013 6:57:31 PM
RE: Efficient XML Parsing Posted by Marco Plaza @ 3/21/2013 5:06:20 AM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/21/2013 2:15:33 PM
RE: Efficient XML Parsing Posted by Marco Plaza @ 3/21/2013 6:28:05 PM
RE: Efficient XML Parsing Posted by Paul Gibson @ 3/21/2013 1:31:38 PM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/21/2013 2:50:30 PM
RE: Efficient XML Parsing Posted by Tamar Granor @ 3/20/2013 9:30:55 PM
RE: Efficient XML Parsing Posted by Paul Gibson @ 3/21/2013 1:35:12 PM
RE: Efficient XML Parsing Posted by Tamar Granor @ 3/22/2013 9:25:46 PM
RE: Efficient XML Parsing Posted by James Frye @ 5/11/2013 4:29:23 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 3/21/2013 2:25:06 AM
RE: Efficient XML Parsing Posted by Paul Gibson @ 3/21/2013 1:34:45 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 3/21/2013 10:19:56 PM
RE: Efficient XML Parsing Posted by Paul Gibson @ 5/8/2013 3:36:24 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 5/9/2013 1:07:22 AM
RE: Efficient XML Parsing Posted by Paul Gibson @ 5/9/2013 2:01:18 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 5/9/2013 2:29:08 PM
RE: Efficient XML Parsing Posted by Paul Gibson @ 5/15/2013 12:27:19 AM
RE: Efficient XML Parsing Posted by Russell Hill @ 5/15/2013 1:11:27 AM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 5/9/2013 2:54:01 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 5/10/2013 1:23:41 AM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 5/10/2013 3:01:55 AM
RE: Efficient XML Parsing Posted by Russell Hill @ 5/10/2013 3:10:19 AM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 5/10/2013 1:09:59 PM
RE: Efficient XML Parsing Posted by Rick Hodgin @ 5/10/2013 3:49:46 PM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/21/2013 2:22:38 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 3/21/2013 10:47:28 PM
RE: Efficient XML Parsing Posted by Jose Mendes @ 3/28/2013 8:12:46 AM
RE: Efficient XML Parsing Posted by Russell Hill @ 3/29/2013 11:57:43 AM
RE: Efficient XML Parsing Posted by Jose Mendes @ 3/30/2013 6:43:29 PM
RE: Efficient XML Parsing Posted by Marco Plaza @ 3/29/2013 7:27:28 PM
RE: Efficient XML Parsing Posted by Jose Mendes @ 3/30/2013 6:44:07 PM