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
theNode
is an element node,nodeName
is a string matching the tag name of that element. For example, iftheNode
represents the element<BOOK>
, thentheNode
.nodeName
is"BOOK"
.
If
theNode
is a text node,nodeName
isnull
. Note that this diverges from the DOM specification, which stipulates thatnodeName
for a text node should be the string"#text"
. If you prefer, you can use the DOM-compliantnodeType
property 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
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.