CDATASection Object
Last Updated: 08-25-2005
Represents an XML CDATA section in the Document Object Model (DOM).

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

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

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.

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

<?xml version="1.0"?>
<?access-control allow="*"?>
    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. -->

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"

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


   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")
         if (oNode.nodeType == Node.CDATA_SECTION_NODE &&
             oNode.nodeName == "#cdata-section")
      { vxmllog("Exception: " + e); }

         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"/>

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