XMLNodeList

From Xojo Documentation

Class (inherits from Object)

Stores the results of an XQL query done by the XQL method of the XMLNode class.

Properties
LastError Length


Methods
Item ToString

Example

The example code below uses this XML. Assign it to a constant called kTestXML:

 <?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>

To get all the player names, you can use "//Player" as the query and loop through the returned XMLNodeList:

// Load XML
Var xml As New XmlDocument
Try
xml.LoadXml(kTestXml)
Catch e As XmlException
MessageBox("XML error: " + e.Message)
End Try

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

// Loop through results and display each name attribute
Var node As XmlNode
For i As Integer = 0 To nodes.Length - 1
node = nodes.Item(i)
MessageBox("Player: " + node.GetAttribute("name"))
Next


See Also

XMLNode class, XMLNode.XQL method