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:
00855435
Vues:
25
Nothing man it's a pleasure :-)
Jaime


>Thanks Jaime, you are my tutor today!
>
>Glenn
>
>>Glenn
>>You can do something like this :
>>for each loElement in oz
>>   ? loElement.Text
>>endfor
>>
>>
>>HTH
>>Jaime
>>
>>>Terrific explanation Lisa, thanks. I do not understand how to get a count of items in the oz object resulting from SelectNodes.
>>>
>>>Thanks
>>>
>>>Glenn
>>>
>>>>----------
>>>>I know the structure of the xml file, since I am the one creating it. What I do is try to put various global settings (similar to .net web.config) in an xml file. (I used to do it with .dbf file).
>>>>----------
>>>>
>>>>OK, that means you can don't have to use a wildcard syntax -- is more efficient not to.
>>>>
>>>>The syntax I'm using is not in the VFP documentation <s>. You asked about how to use the MSXML DOM objects, so I was trying to teach you how to get where you want to go using those objects.
>>>>
>>>>The two methods I used, selectNodes() and selectSingleNodes(), are methods of Node, I believe -- I can't remember how exactly this works in MS's object model, this is not standard across parsers, it's just the way somebody decides to implement their class heirarchy, but I think that anything that descends from Node (this includes a document object and a bunch of other things) would have these two methods.
>>>>
>>>>The argument I used for each method is XPATH. This is a standard, just like XML, and is not something peculiar to MSXML. You can read about XPATH by reading about the standard -- I will explain my examples here and you can go wherever you want to go with this.
>>>>
>>>>First, an explanation of the two methods I used.
>>>>
>>>>SelectNodes gives you a collection of nodes that matches your XPATH filter or query. SelectSingleNode gives you a reference to the first node that matches your filter or query -- because obviously there can be more than one.
>>>>
>>>>I'm still not sure whether you want a set of nodes or a single node, that's why I gave you both. But, now that I know you know the structure of the file, I would use the following to get the appropriate collection of nodes:
>>>>
>>>>oz = ox.selectnodes("/service/add")
>>>>
>>>>This is the syntax that drills down from the root to the set of nodes you really want, which apparently all exist on one level of your tree (if not, you do it differently, but you can read about XPATH yourself. <s>)
>>>>
>>>>Now I could iterate through this collection, using syntax such as:
>>>>
>>>>? oz.item[ii].getattribute("key")
>>>>? oz.item[ii].getattribute("value")
>>>>
>>>>... to get the information you're after. Note, again that getAttribute is not particularly standard, it's just something available to you with MSXML's specific set of objects, but most DOM implementations have something like this.
>>>>
>>>>If, instead, you wanted just the information for a particular key value, I suggested you do something like this (again, this time I'm explicitly drilling down without using anything like a wild card):
>>>>
>>>>mykey = "key2"
>>>>oz = ox.selectSingleNode("/service/add[@key='"+mykey+"']/@value").text
>>>>* oz is now the string "value2".
>>>>
>>>>Here I've said "give me the add node that is the child of the root service where the key equals the value I'm looking for. Having found this key, I want a reference to its attribute child node with the name 'value'". Then I used the .text property of this attribute node to get the text contents of this object.
>>>>
>>>>So, oz now has the string value (not an object) that you want. If I'd left off the .text you would have a reference to the add node's attribute child node. If I'd left off the /@value also, you would have a reference to the add node, and could use getAttribute on it as I did above.
>>>>
>>>>Writing kind of fast, let me know if this does not make sense.
>>>>
>>>>>L<
Why do programs stop working correctly as soon as you leave the Fox?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform