XML.nodeName Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
XML.nodeName Property Flash 5

the name of the current node read/write
theNode.nodeName

Description

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.

Example

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);   } }

See Also

XML.nodeType, XML.nodeValue



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net