Back to Contents


The NodeList class

Summary:

See also: Classes and Objects, XML Utilities


Syntax

The NodeList class holds a list of DomNode objects created from a selection method.

Syntax:

om.NodeList

Notes:

  1. A NodeList object is created from a DomNode.selectByTagName() or DomNode.selectByPath() method.

Methods:

Object Methods
Name Description
item( index INTEGER )
 
RETURNING om.DomNode
Returns the DomNode object at the given position (first is 1). Returns NULL if the item does not exist.
getLength( )
 
RETURNING INTEGER
Returns the number of items in the list.

Usage

A NodeList object contains a list of the child objects of the DomNode from which it was created, selected by Tag Name or Path.  Use the DomNode methods to create the NodeList, as shown in the examples below.

The XPath syntax of the selectByTagName() and selectByPath() methods of om.DomNode class is limited to:

     { / | // } TagName [ [@AttributeName="Value"] ] [...]

Once the NodeList object is created, the following Object methods are available:

item() - This method returns the DomNode that is at the specified position in the list.

getLength() - This method returns the total number of DomNodes in the list.


Examples

Example 1: Search for child nodes by tag name:

01 MAIN
02   DEFINE nl om.NodeList
03   DEFINE r, n om.DomNode
04   DEFINE i INTEGER
05
06   LET r = ui.Interface.getRootNode()
07   LET nl = r.selectByTagName("Form")
08
09   FOR i=1 to nl.getLength()
10     LET n = nl.item(i)
11     DISPLAY n.getAttribute("name")
12   END FOR
13
14 END MAIN

Example 2: Search for child nodes by XPath:

01 MAIN
02   DEFINE nl om.NodeList
03   DEFINE r, n om.DomNode
04   DEFINE i INTEGER
05
06   LET r = ui.Interface.getRootNode()
07   LET nl = r.selectByPath("//Window[@name=\"screen\"]")
08
09   FOR i=1 to nl.getLength()
10     LET n = nl.item(i)
11     DISPLAY n.getAttribute("name")
12   END FOR
13
14 END MAIN