XML.nodeName Property | Flash 5 |
the name of the current node | read/write |
The nodeName string property reflects the name of theNode, where theNode can be an XML or XMLnode instance. 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, if theNode represents the element <BOOK>, then theNode.nodeName is "BOOK".
If theNode is a text node, nodeName is null. Note that this diverges from the DOM specification, which stipulates that nodeName for a text node should be the string "#text". If you prefer, you can use the DOM-compliant nodeType property instead.
We can use nodeName to check whether the current node has the element name we're seeking. For example, here we extract all the content of H1 tags on the first level of an XML document (this example also checks 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.toUppercase() = = "H1") { trace(myDoc.childNodes[i].firstChild.nodeValue); } }