CDATASection Object
Last Updated: 08-25-2005
Represents an XML CDATA section 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 CDATASection object is a specialized node object in an XML document that contains a CDATA section.
Prior to revision 3, CDATA section nodes in an XML document fetched by a data element are treated the same as text nodes. In revision 3 and later, they are treated independently, so you can now distinguish between the two.
Examples

Here is a sample XML document that includes a CDATA section:

<?xml version="1.0"?>
<?access-control allow="*"?>
<data>
    A text node cannot contain certain special characters.
    <![CDATA[However, a CDATA-section node can contain all characters 
except for a special escape sequence.  For example, less than (<) and 
greater than (>) are allowed here.]]>
    <!-- Note: In the DOM, the whitespace, including line ending 
characters, between one visible element and another is considered a 
text node. So, for example, there is a text node preceding this comment 
and another text node following it. -->
</data>

The following program illustrates fetching an XML document, counting the CDATA section nodes and the text nodes, and reporting the results.

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

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

   <script>
   <![CDATA[

   var aValues = [];
   var nTextNodeCount = 0;
   var nCDATASectionNodeCount = 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 &&
             oNode.nodeName == "#text")
         {
            aValues.push(oNode.nodeValue);
            nTextNodeCount++;
         }
         if (oNode.nodeType == Node.CDATA_SECTION_NODE &&
             oNode.nodeName == "#cdata-section")
         {
            aValues.push(oNode.nodeValue);
            nCDATASectionNodeCount++;
         }
      }
   }
   catch(e)
      { vxmllog("Exception: " + e); }
   ]]>
   </script>

   <form>
      <block>
         The document has <value expr="nTextNodeCount"/> text nodes and 
           <value expr="nCDATASectionNodeCount"/> CDATA section nodes.
         <break size="small"/>
         The values are
         <break size="small"/>
         <foreach item="oValue" array="aValues">
            <value expr="oValue"/>
            <break size="small"/>
         </foreach>
      </block>
   </form>
</vxml>


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