
XML.nodeName Property
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
935
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
XML.nodeName Property
the name of the current node
Flash 5
read/write
theNode.nodeName
Description
The nodeName string property reflects the name of theNode, where ...