Help Center

Local Navigation

Object: TreeWalker

Availability

BlackBerry® Device Software version 4.6 or later

The TreeWalker object enables you to navigate the document tree or subtree. This object is similar to the NodeIterator objects, except that TreeWalker presents nodes in a tree-oriented view, rather than the list view presented by NodeIterator. This allows you to use TreeWalker to navigate directly to a parent or child, rather than simply up and down in the list using NodeIterator.

Create a TreeWalker using Document.createTreeWalker().

TreeWalker properties

Property name

Type

Description

Status

Availability

currentNode

Node

Specifies the current position of the TreeWalker.

writable

4.6 or later

expandEntityReferences

boolean

Returns whether or not the TreeWalker expands the entity references it encounters as it traverses the document.

read only

4.6 or later

filter

NodeFilter

Returns the NodeFilter used to filter nodes for traversal.

read only

4.6 or later

root

Node

Returns the Node at which the TreeWalker begins traversing the document.

read only

4.6 or later

whatToShow

unsigned long

Returns which node types are presented by the TreeWalker. The value may be one or more of:

  • 0xFFFFFFFF = SHOW_ALL
  • 0x00000001 = SHOW_ELEMENT
  • 0x00000002 = SHOW_ATTRIBUTE
  • 0x00000004 = SHOW_TEXT
  • 0x00000008 = SHOW_CDATA_SECTION
  • 0x00000010 = SHOW_ENTITY_REFERENCE
  • 0x00000020 = SHOW _ENTITY
  • 0x00000040 = SHOW_PROCESSING_INSTRUCTION
  • 0x00000080 = SHOW_COMMENT
  • 0x00000100 = SHOW_DOCUMENT
  • 0x00000200 = SHOW_DOCUMENT_TYPE
  • 0x00000400 = SHOW_DOCUMENT_FRAGMENT
  • 0x00000800 = SHOW_NOTATION

Multiple values may be specified using a bitwise OR.

Note that because attributes, entities, and notations are not the child of any other node, they never appear in the TreeWalker’s logical view unless they are defined as the root of the TreeWalker object. If the respective object is not defined as the root, then SHOW_ATTRIBUTE, SHOW_ENTITY, and SHOW NOTATION have no meaning.

read only

4.6 or later

TreeWalker methods

Method name

Description

Availability

firstChild()

Moves the TreeWalker to the first visible child of the current node.

4.6 or later

lastChild()

Moves the TreeWalker to the last visible child of the current node.

4.6 or later

nextNode()

Moves the TreeWalker to the next visible node in the document order, relative to the current node.

4.6 or later

nextSibling()

Moves the TreeWalker to the next sibling of the current node.

4.6 or later

parentNode()

Moves the TreeWalker to the closest visible ancestor node of the current node.

4.6 or later

previousNode()

Moves the TreeWalker to the previous visible node in the document order, relative to the current node.

4.6 or later

previousSibling()

Moves the TreeWalker to the previous sibling of the current node.

4.6 or later

Method: TreeWalker.firstChild()

Availability

BlackBerry® Device Software version 4.6 or later

The firstChild() method moves the TreeWalker to the first visible child of the current node. The value of TreeWalker.currentNode is updated to reflect the TreeWalker’s new location in the tree.

If no visible children exist in the TreeWalker’s view, the value of TreeWalker.currentNode remains unchanged.

Syntax

TreeWalker.firstChild()

Parameters

None.

Return values

Returns the node, or null, if the current node has no visible children in the TreeWalker’s logical view.

Exceptions

None.

Method: TreeWalker.lastChild()

Availability

BlackBerry® Device Software version 4.6 or later

The lastChild() method moves the TreeWalker to the last visible child of the current node. The value of TreeWalker.currentNode is updated to reflect the TreeWalker’s new location in the tree.

If no visible children exist in the TreeWalker’s view, the value of TreeWalker.currentNode remains unchanged.

Syntax

TreeWalker.lastChild()

Parameters

None.

Return values

Returns the node, or null, if the current node has no visible children in the TreeWalker’s logical view.

Exceptions

None.

Method: TreeWalker.nextNode()

Availability

BlackBerry® Device Software version 4.6 or later

The nextNode() method moves the TreeWalker to the next visible Node in the document order, relative to the current node. The value of TreeWalker.currentNode is updated to reflect the TreeWalker’s new location in the tree.

If no node exists after the current node in the TreeWalker’s view, the value of TreeWalker.currentNode remains unchanged.

Syntax

TreeWalker.nextNode()

Parameters

None.

Return values

Returns the node, or null, if there is no node after the current node in the TreeWalker’s logical view.

Exceptions

None.

Method: TreeWalker.nextSibling()

The nextSibling() method moves the TreeWalker to the next sibling of the current node. The value of TreeWalker.currentNode is updated to reflect the TreeWalker’s new location in the tree.

If no visible sibling node exists after the current node in the TreeWalker’s view, the value of TreeWalker.currentNode remains unchanged.

Syntax

TreeWalker.nextSibling()

Parameters

None.

Return values

Returns the node, or null, if the current node has no visible siblings after it in the TreeWalker’s logical view.

Exceptions

None.

Method: TreeWalker.parentNode()

Availability

BlackBerry® Device Software version 4.6 or later

The parentNode() method moves the TreeWalker to the closest visible ancestor node of the current node. The value of TreeWalker.currentNode is updated to reflect the TreeWalker’s new location in the tree.

If no visible ancestor node exists in the TreeWalker’s view, the value of TreeWalker.currentNode remains unchanged.

Syntax

TreeWalker.parentNode()

Parameters

None.

Return values

Returns the node, or null, if the current node has no visible ancestor in the TreeWalker’s logical view.

Exceptions

None.

Method: TreeWalker.previousNode()

The previousNode() method moves the TreeWalker to the previous visible Node in the document order, relative to the current node. The value of TreeWalker.currentNode is updated to reflect the TreeWalker’s new location in the tree.

If no node exists before the current node in the TreeWalker’s view, the value of TreeWalker.currentNode remains unchanged.

Syntax

TreeWalker.previousNode()

Parameters

None.

Return values

Returns the node, or null, if there is no node before the current node in the TreeWalker’s logical view.

Exceptions

None.

Method: TreeWalker.previousSibling()

Availability

BlackBerry® Device Software version 4.6 or later

The previousSibling() method moves the TreeWalker to the previous sibling of the current node. The value of TreeWalker.currentNode is updated to reflect the TreeWalker’s new location in the tree.

If no visible sibling node exists before the current node in the TreeWalker’s view, the value of TreeWalker.currentNode remains unchanged.

Syntax

TreeWalker.previousSibling()

Parameters

None.

Return values

Returns the node, or null, if the current node has no visible sibling before it in the TreeWalker’s logical view.

Exceptions

None.

Next topic: Object: UIEvent

Was this information helpful? Send us your comments.