
XML.nodeValue Property
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
937
Technically, ActionScript implements so-called attribute, document, and document_type
nodes in addition to element and text nodes, but we don’t have direct access to them as
objects. For example, we can manipulate the attributes of a node through the
attributes
property, but we do not have direct access to attribute nodes themselves. Similarly, we have
access to the
DOCTYPE tag of a document through the docTypeDecl property, but we do not
have direct access to the document_type node itself.
Element nodes correspond to XML or HTML tags. For example, in the XML fragment
<P>what is your favorite color?</P>, the P tag is represented in an XML object hierarchy
as an element node (
nodeType 1). The text contained by a tag in XML source code—for
example, the text “what is your favorite color?”—is represented as a text node (
nodeType 3).
CDATA section nodes are irreversibly converted to text nodes when they are parsed, as
described under XML.parseXML().
Example
We can operate on a node conditionally, based on its nodeType. For example, here we
remove all the empty text nodes that are children of
theNode:
// Loop through all children of theNode
for (var i=0; i < theNode.childNodes.length; i++) {
// If the current node is a text node...
if (theNode.childNodes[i].nodeType ...