org.w3c.dom
Interface ElementTraversal


public interface ElementTraversal

The ElementTraversal interface is a set of properties on the Element object, which allow an author to easily navigate between elements.

Note: This interface has not yet been accepted for inclusion in the W3C DOM 3 specification. It may be removed from the JSR 280 specification or added to a different namespace in a subsequent version of the specification.

Four of the properties, firstElementChild, lastElementChild, previousElementSibling, and nextElementSibling, each provide a live reference to another element with the defined relationship to the current element, if the related element exists. The fifth property, childElementCount, exposes the number of child elements of an element, for preprocessing before navigation. A conforming implementation must implement all five methods. An implementation may implement similar interfaces in other specifications, but such implementation is not required for conformance to this specification, if the implementation is designed for a minimal code footprint.

This interface must be implemented on all elements, regardless of their namespace. For the purpose of ElementTraversal, an entity reference node which represents an element must be treated as an element node. Navigation must be irrespective of namespace, e.g. if an element in the HTML namespace is followed by element in the SVG namespace, nextElementSibling will allow you to navigate from the HTML element to the SVG element.


Method Summary
 int getChildElementCount()
          Retrieves the number of child elements.
 Element getFirstElementChild()
          Retrieves the first child element.
 Element getLastElementChild()
          Retrieves the last child element.
 Element getNextElementSibling()
          Retrieves the next sibling element.
 Element getPreviousElementSibling()
          Retrieves the previous sibling element.
 

Method Detail

getChildElementCount

public int getChildElementCount()
Retrieves the number of child elements.

Returns:
the current number of element nodes that are immediate children of this element. 0 if this element has no child elements.

getFirstElementChild

public Element getFirstElementChild()
Retrieves the first child element.

Returns:
the first child element node of this element. null if this element has no child elements.

getLastElementChild

public Element getLastElementChild()
Retrieves the last child element.

Returns:
the last child element node of this element. null if this element has no child elements.

getNextElementSibling

public Element getNextElementSibling()
Retrieves the next sibling element.

Returns:
the next sibling element node of this element. null if this element has no element sibling nodes that come after this one in the document tree.

getPreviousElementSibling

public Element getPreviousElementSibling()
Retrieves the previous sibling element.

Returns:
the previous sibling element node of this element. null if this element has no element sibling nodes that come before this one in the document tree.


Copyright © 2000,2004 World Wide Web Consortium (W3C). See the Copyright Notice for details.