XML.nextSibling Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
XML.nextSibling Property Flash 5

a reference to the node after this node read-only
theNode.nextSibling

Description

The nextSibling property returns the node object after theNode in the current level of the XML object hierarchy (theNode can be an XML or XMLnode instance). If there is no node after theNode, nextSibling returns null. In the following XML source fragment, the CONTENT node is the nextSibling of the USER node:

<MESSAGE><USER>gray</USER><CONTENT>hi</CONTENT></MESSAGE>

Example

Typically, the nextSibling property is used to traverse (move through or examine) an XML object hierarchy. For example, to view all the children of theNode in the order they appear, we can use:

for (var child = theNode.firstChild; child != null; child = child.nextSibling) {   trace("found node: " + child.nodeName); }

By extending our loop into a function, we can recursively traverse every node in an XML object hierarchy, as follows:

function showNodes (node) {   trace(node.nodeName + ": " + node.nodeValue);   for (var child = node.firstChild; child != null; child = child.nextSibling) {     showNodes(child);   } }     // Invoke the function on our node or document showNodes(myDoc);

Note that in both traversal examples shown, text nodes show up without a name, as described under the nodeName entry.

See Also

XML.childNodes, XML.firstChild, XML.lastChild, XML.nodeName, XML.nodeValue, XML.previousSibling



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net