Name
XML.nodeName Property — the name of the current node
Availability
Flash 5
Synopsis
theNode.nodeName
Access
Read/write
Description
The nodeName string property reflects the name of
theNode. Since only two node types are
supported by ActionScript (element nodes and
text nodes), nodeName has
only two possible values:
If
theNodeis an element node,nodeNameis a string matching the tag name of that element. For example, iftheNoderepresents the element<BOOK>, thentheNode.nodeNameis"BOOK".
If
theNodeis a text node,nodeNameisnull. Note that this diverges from the DOM specification, which stipulates thatnodeNamefor a text node should be the string"#text". If you prefer, you can use the DOM-compliantnodeTypeproperty instead.
Example
We can use nodeName to check whether the current
node is the type of element we’re seeking. For example, here we
extract all the content of H1 tags on the first
level of an XML document (this example checks only for tags named
H1, not for tags named h1
with a lowercase h):
myDoc = new XML('<H1>first heading</H1><P>content</P>' +
'<H1>second heading</H1><P>content</P>');
for (i = 0; i < myDoc.childNodes.length; i++) {
if (myDoc.childNodes[i].nodeName == "H1") {
trace(myDoc.childNodes[i].firstChild.nodeValue);
}
}See Also
XML
.nodeType,
XML
.nodeValue
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