XML technologies / XML / XML in a Nutshell / DOM reference / Object reference / NodeList

(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)

The interface NodeList represents an ordered list that can be used by DOM classes. A NodeList is an array of Node objects indexed from 0. The list is read-only. Since there is no direct way to create, add or remove nodes in a NodeList, this class cannot be used as a generic list.

Java example

// Gibt den textuellen Inhalt eines Elements aus.
NodeList nlChildren = elem.getChildNodes(  );
Node ndChild;

for (int iNode = 0; iNode < nlChildren.getLength(  ); iNode++) {
    ndChild = nlChildren.item(iNode);

    if (ndChild.getNodeType(  ) == Node.TEXT_NODE) {
System.out.println(ndChild.getNodeValue(  ));
    }
}

 

Attribute

The interface NodeList defines a single attribute:

 

length: unsigned long

The number of Node objects in the list.

Java binding
public long getLength( );

 

Method

The interface NodeList defines a single method:

 

item: index

Returns a reference to the Node object at the specified position index. If the index is invalid, it returns null. This is the case when the specified index is < 0 or >= the length attribute of the NodeList.

Argument

  • index: unsigned long

    The index of the node to read from the list, starting at 0.

Java binding
public Node item(long index);

  

 

 

 

back to top