XML.nextSibling Property | Flash 5 |
a reference to the node after this node | read-only |
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>
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.
XML.childNodes, XML.firstChild, XML.lastChild, XML.nodeName, XML.nodeValue, XML.previousSibling