Name

XML.nodeValue Property — the value of the current node

Availability

Flash 5

Synopsis

theNode.nodeValue

Access

Read/write

Description

The nodeValue property reflects the string value of theNode. 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.

In practice, nodeValue is normally used only with text nodes. 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";

Although we may explicitly retrieve the value of a text node using nodeValue, the toString( ) method implicitly returns a node’s value when it is used in a string context. Therefore, this code displays the text node’s text in the Output window:

trace(myDoc.firstChild.firstChild);

See Also

XML .nodeName, XML .nodeType

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.