how can i get the elements by name
and then the temp_c value?
i can’t believe that there is only a Child by index method.
i guess i need to add a Extends method to find something by name.
XQL is your friend here.
Check the docs… it could return several nodes, not just one, so you start with an XMLNodeList
Something like this should help:
Dim ListNodes As XmlNodeList = TheXMLNode.XQL("//temp_c")
dim theNode as XmlNode = ListNodes.item(0)
dim theValue as string = theNode.FirstChild.Value
Remember that it all depends on the structure of your XML
//nodeName will return all the nodes with that name in your document and sometime it could be misleading.
I usually prefer a more difensive solution using the path starting from the documentNode
For example in your case, say theXML is the XMLDocument:
Var theNodes as XMLNodeList=theXML.documentElement(“data/METAR/temp_c”)
using this strategy you can use as starting node any internal node you can identify.
More over you can select between siblings nodes: theXML.documentElement(“data[@num_result=”“2"”]/METAR/temp_c")
In any case the value could be not existent a better XQL could be (valid for both strategy):
now if you get a list of noted (XQL result length >0) you are sure that is the desired text node and now you can get the value.
thank you all both answering my question.
i overlooked this query feature in help.
Youre not the only one (Thanks Jeff).