XML

Im looking at the XMLNodeList Page in the documents.

Here is the code:

[code]// Load XML
Dim xml As New XmlDocument
Try
xml.LoadXml(kTestXml)
Catch e As XmlException
MsgBox("XML error: " + e.Message)
End Try

// Display all the Player names
Dim nodes As XmlNodeList
nodes = xml.XQL("//Player") // Find all Player nodes in XML

// Loop through results and display each name attribute
Dim node As XmlNode
For i As Integer = 0 To nodes.Length-1
node = nodes.Item(i)
MsgBox("Player: " + node.GetAttribute(“name”))
Next[/code]

Here is the example XML

<?xml version="1.0" encoding="UTF-8"?> <League> <Team name="Seagulls"> <Player name="Bob" position="1B" /> <Player name="Tom" position="2B" /> </Team> <Team name="Pigeons"> <Player name="Bill" position="1B" /> <Player name="Tim" position="2B" /> </Team> <Team name="Crows"> <Player name="Ben" position="1B" /> <Player name="Ty" position="2B" /> </Team> </League>

What I can’t figure out is the proper user of the search terms.

nodes = xml.XQL("//Player") // Find all Player nodes in XML  

How does the search work and why is there a “//” in the search term?

Also Given the XML that is shown on the manual page why does the phrase “name” work here?

 MsgBox("Player: " + node.GetAttribute("name"))

Finally Given:

<?xml version="1.0" ?> <response> <result> success </result> <get_users_response> <users> <user> geoff </user> <user> jason </user> <user> thom </user> </users> </get_users_response> </response>

What doI use to get the 3 users from this?

[quote=31177:@Jay Menna]nodes = xml.XQL("//Player") // Find all Player nodes in XML [/code]

How does the search work and why is there a “//” in the search term?
[/quote]
This is a specific type of syntax for XQL/XPath. More information here: http://www.w3schools.com/xpath/ (this URL is also on the XQL page in the LR).

[quote=31177:@Jay Menna]Also Given the XML that is shown on the manual page why does the phrase “name” work here?
MsgBox("Player: " + node.GetAttribute(“name”))[/quote]
“name” is an attribute on that node.

With your XML in kXML, this code will display the three users:

[code] // Load XML
Dim xml As New XmlDocument
Try
xml.LoadXml(kXML)
Catch e As XmlException
MsgBox("XML error: " + e.Message)
End Try

// Display all the Player names
Dim nodes As XmlNodeList
nodes = xml.XQL("//user") // Find all user nodes in XML

// Loop through results and display each name attribute
Dim node As XmlNode
For i As Integer = 0 To nodes.Length-1
node = nodes.Item(i)
MsgBox("user: " + node.FirstChild.Value.Trim)
Next[/code]