Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Newbie question on processing XML file
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
XML, XSD
Divers
Thread ID:
00854652
Message ID:
00855471
Vues:
16
--------------
And how would you suggest to handle the XML file if the structure would be more complicated, like:
[..]
-----------------

In this case you want to do a selecxtNodes where the path is something like "all the nodes directly under the root" or "directly under the node 'service'", correct?


This is a simple problem, really, just define the collection you're looking for. I'm guessing:

oy = ox.selectNodes("service/*") && note: left off the first slash
&& because I don't know if it's root

Now you have a collection through which you can check for "add" nodes. This is why I said, the first time, that you have to understand that these methods are not properties of the document, but of nodes in general. (This is quite important to reiterate, as people who are used to writing SQL statements sometimes have to learn to think a little differently when things are tree-shaped <s>. Drill-down through a potentially-unlimited level of children comes with the territory, except when you're talking about attributes rather than other types of nodes.)

You can selectNodes("./add") for each of the items in the collection -- doing a for each as Jaime showed you or like this with the item reference, which I'm using purely to avoid writing the loop <g>:

oz = oy.item[0].selectnodes("./add")

The "." is XPATH for "current context" and the "*" in the expression above is, of course, "any child". If I was concerned about the type of children, and only wanted elements rather than potential children of other node types, or only wanted elements of any particular pattern, I could have filtered the * in the first expression.

>L<
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform