Class

XMLNodeList


Description

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

Properties

Name

Type

Read-Only

Shared

LastError

Integer

Length

Integer

Methods

Name

Parameters

Returns

Shared

Item

Index As Integer

XMLNode

ToString

[WrapperTag As String]

String

Property descriptions


XMLNodeList.LastError

LastError As Integer

The last error code that was received.


XMLNodeList.Length

Length As Integer

The number of nodes in the list.

Method descriptions


XMLNodeList.Item

Item(Index As Integer) As XMLNode

Retrieves the specified XML node from the list and returns it as an XMLNode. The Index parameter is zero-based.


XMLNodeList.ToString

ToString([WrapperTag As String]) As String

Returns a String representation of the nodes. The optional parameter WrapperTag puts a tag around the NodeList to make it parsable.

Sample code

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

Compatibility

Desktop, console, web and iOS project types on all supported operating systems.

See also

Object parent class; XMLNode class, XMLNode.XQL method