Most efficient way to get XMLNode item

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

You are overlooking XQL see http://www.w3schools.com/xml/xquery_intro.asp

I had a feeling…
I use it in the line
Dim nodes As XmlNodeList = TheXMLNode.XQL("//"+DesiredNodeName)

…but I’m guessing that if I dig into learning about XQL, there’s a way to just extract the value directly without needing the subsequent 3 lines in my method?

Dim nodes As XmlNodeList = TheXMLNode.XQL("//"+DesiredNodeName)
dim theNode as XmlNode = nodes.item(0)
dim theValue as string = XmlNode.FirstChild.Value

This is not unique to Xojo. Any XML node that contains a value

<comedy>HAHA</comedy>

is really 2 nodes. A node named “comedy” which contains an unnamed textnode with a value “HAHA”. It may look like it should be a single node with name “comedy” and value “HAHA”, but it is not. That’s just the XML spec.

Tim, I’ve never seen it described as “an unnamed node” but that clarifies everything and it all makes complete sense now!