TextNode Object
Last Updated: 08-19-2005
Represents an XML text node in the Document Object Model (DOM).

Properties
data Retrieves the text stored within a TextNode, CDATASection, or Comment.

Methods
substringData Extracts a range of characters from the contents of a TextNode, Comment, or CDATASection.

Remarks
The TextNode object is a specialized node object in an XML document that contains text data.
Prior to revision 3, any whitespace that appears between nodes in an XML document fetched by a data element is ignored. In revision 3 and later, it is no longer ignored. As a result, the DOM in revision 3 will reflect more text nodes than in prior revisions.
Examples

The first example below uses the following data.

<?xml version="1.0"?>
<?access-control allow="*"?>
<tale>
Once upon a time in a land far, far, away...
</tale>

The following program prints the contents of the TextNode contained within an element node to the debug log. The element node happens to be the root document element.

<vxml version="2.0">
   <data name="oData" src="quote.exml"/>
   <form id="main">
      <script>
         var oRoot = oData.documentElement;
         vxmllog(oRoot.firstChild.data);
       </script>
   </form>
</vxml>

The next example uses the following data.

<?access-control allow="*"?>
<r>
  <ch1/>
  <ch2/>

</r>

Prior to revision 3, the document root element (r) is considered to have just two children: the element nodes with nodeNames "ch1" and "ch2". In revision 3 and later, the document root element has five children:

  1. The text node for the new line and spaces between the root element and the element node with nodeName "ch1".
  2. The element node with nodeName "ch1".
  3. The text node for the new line and spaces between the element node with nodeName "ch1" and the element node with nodeName "ch2".
  4. The element node with nodeName "ch2".
  5. The text node for the two new lines between the element node with nodeName "ch2" and the closing tag of the root element.

Execution of the following program will demonstrate the new behavior.

<vxml version="2.1"
   xmlns="http://www.w3.org/2001/vxml">

   <data src="sample.xml" name="oData"/>

   <script>
   <![CDATA[

   var nTextNodeCount = 0;
   var nElementNodeCount = 0;

   try {
      var oRoot = oData.documentElement;
      for (var i = 0; i < oRoot.childNodes.length; i++)
      {
         var oNode = oRoot.childNodes.item(i);
   
         if (oNode.nodeType == Node.TEXT_NODE)
         { nTextNodeCount++; }
         if (oNode.nodeType == Node.ELEMENT_NODE)
         { nElementNodeCount++; }
      }
   }
   catch(e)
      { vxmllog("Exception: " + e); }
   ]]>
   </script>

   <form>
      <block>
         The document has <value expr="nTextNodeCount"/> text nodes and 
           <value expr="nElementNodeCount"/> element nodes.
      </block>
   </form>
</vxml>


[24]7 Inc.| Terms of Service| Privacy Policy| General Disclaimers