I’'m not a newbie by a long shot, but I feel like this is a really basic question–I’m just drawing a blank on it right now:
Given some XML returned by a web service, something like this:
HAHA OOHEEK
What is the most efficient way to extract a value. For example, if I wanted the drama value, what’s the most efficient code that would find it in the XML and return OOH.
Right now, I’ve got the following, which seems to work flawlessly, but I feel like I’m overlooking a far more elegant solution since I’m not super familiar with Xojo’s built-in XML functionality:
[code]
'some initialization of things left out here and everything re-typed by hand, so consider the following to be pseudo-code:
XMLFromTheWholeString= new XmlDocument(StringReturnedByWebService) 'Convert web service string to XMLDoc
TheXMLNode=XMLFromTheWholeString.FirstChild 'This gets me to the “YourResults” node of the XML
DesiredNodeName =“drama” 'or whatever node I’m actually interested in
try
Dim nodes As XmlNodeList = TheXMLNode.XQL("//"+DesiredNodeName)
theValue=nodes.item(0).ToString 'I know there’s only one item with the name I’m looking for
thenum=len(TheNodeName)
return theValue.Mid(theNum+3,len(TheValue)-(2*theNum+5)) 'gets rid of the start/end tags
end try
return “” 'returns an empty string if no match found[/code]
I created the above as a method that takes parameters for TheXMLNode and DesiredNodeName, and it’s working flawlessly–but I can’t shake the feeling that I’m overlooking something far simpler