Gathering Information About the Node List

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Developer's Guide

Gathering Information About the Node List

You can retrieve the length of the node list from the length property. Among other things, the length can be used for iterating through the list of children. For example, the following Microsoft® JScript® code loops through the children of elem1, searching for a child element with the text value of "hello world". If such a child exists, the index of that child is assigned to the variable "helloWorldIndex".

for (i = 0;i < elem1.childNodes.length;i++){
  if (elem1.childNodes.item(i).text == "hello world")
    helloWorldIndex = i;
  }

In Microsoft Visual Basic® Scripting Edition (VBScript), the same code would look like the following.

For i = 0 to elem1.childNodes.length - 1
  if (elem1.childNodes.item(i).text = "hello world") Then
    helloWorldIndex = i
Next

You can also move through the node list using the nextNode method.

See Also

length Property (IXMLDOMNodeList)