XML.nodeValue Property

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

the value of a node, as a string read/write
theNode.nodeValue

Description

The nodeValue property reflects the string value of theNode, where theNode can be an XML or XMLnode instance. Since only two node types (element nodes and text nodes) are supported by ActionScript, nodeValue has only two possible values:

  • If theNode is an element node, nodeValue is null.

  • If theNode is a text node, nodeValue is the text contained by the node.

To assign new text to an existing text node, we use nodeValue as follows:

// Create a new XML document myDoc = new XML('<H1>first heading</H1><P>content</P>');     // Change the text contained by the H1 tag myDoc.firstChild.firstChild.nodeValue = "My Life Story";

To retrieve the text of a text node, we simply read its nodeValue property:

trace(myDoc.firstChild.firstChild.nodeValue);

Note that, in nodeValue, the predefined entities &lt;, &gt;, &amp;, &quot;, and &apos; are represented as the literal characters <, >, &, ", and '. To obtain the source code for a node, including uninterpreted entities, use XML.toString( ). For more details, see XML.parseXML( ).

When a node is used in a string context, Flash uses XML.toString( ), not nodeValue, to represent its value:

// Force an implicit datatype conversion. Calls toString( ). trace(myDoc.firstChild.firstChild); // Same as: trace(myDoc.firstChild.firstChild.toString());

See Also

XML.nodeName, >, XML.parseXML( ), XML.toString( )



    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