Name
XML.nextSibling Property — a reference to the node after this node
Availability
Flash 5
Synopsis
theNode.nextSibling
Access
Read-only
Description
The nextSibling property returns the node object
after theNode in the current level of the
XML object hierarchy. 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
The nextSibling property is typically used to
traverse (move through) an XML object hierarchy.
For example, to view all the children of
theNode in the order they appear, we may
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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access