Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need some XML parsing help
Message
De
25/03/2005 11:08:13
 
 
À
25/03/2005 07:46:28
Information générale
Forum:
Visual FoxPro
Catégorie:
XML, XSD
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
00999113
Message ID:
00999161
Vues:
18
Glenn,

>I need to parse out several bits of data from a XML structure but I know only how to do this with "brute force" string parsing. My guess that there is a more elegant XML Dom method which can easily navigate and extract the needed data...

I'm sure someone else will give you the DOM info, but I'm curious about which "brute force" string parsing technique you are using. FWIW, I have found that STREXTRACT() is very useful, particularly when the XML you are parsing contains just one "record," as in the case you present here.

>
> <datafield tag="020" ind1=" " ind2=" ">
>    <subfield code="c">$19.95 ($31.00 Can.)</subfield>
>  </datafield>
>
>We need the price information as in subfield code "c" and:

I would do something like:
c020 = STREXTRACT(cXML, [<datafield tag="020"], [</datafield])
c020c = STREXTRACT(c020, [<subfield code="c">], [</subfield>])
>
>  <datafield tag="260" ind1=" " ind2=" ">
>    <subfield code="a">San Francisco, CA :</subfield>
>    <subfield code="b">Collins,</subfield>
>    <subfield code="c">1995.</subfield>
>  </datafield>
>
>We also need the data from Datafield tag "260" subfield "b" and "c".

I would parse this one like this:
c260 = STREXTRACT(cXML, [<datafield tag="260"], [</datafield])
c260b = STREXTRACT(c260, [<subfield code="b">], [</subfield>])
c260c = STREXTRACT(c260, [<subfield code="c">], [</subfield>])
You may find that techniques like this are faster than using a DOM. Also, note that VFP9 has added a new flag value of 4 on STREXTRACT() that will include the beginning and ending delimiters in the returned value -- making it easy to "lift out" entire sections of a larger XML document with surrounding tags intact, in case you need to break out parts of the XML into its own document for some reason.
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform