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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.