Comment Object
Last Updated: 08-25-2005
Represents an XML comment 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 Comment object is a specialized node object in an XML document that contains a comment.
Prior to revision 3, any comments that appear in an XML document fetched by a data element are ignored. In revision 3 and later, comments are no longer ignored.
Examples

The following example demonstrates using the data element to fetch an XML document, then traversing the document to extract information from it and ignore anything, such as comments, that is not relevant. Suppose the XML document that is fetched looks like the following:

<?xml version="1.0"?>
<?access-control allow="*"?>
<review>
  Actor John Smith and director Jane Doe are right on target 
  <!-- colloquialism --> 
  in the new flick 
  <!-- colloquialism -->
  Skippy Goes to Hollywood. Smith is a 
  <!-- passive voice --> 
  great singer.
</review>

Here is a program that could be used to process the document and log the review provided in it. The program ignores any nodes, including comment nodes, that are not text or CDATA section nodes:

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

<form>
  <block>
    <data name="dom" src="comment.xml"/>
    <script><![CDATA[
      var root = dom.documentElement;
      var nodeCount = root.childNodes.length;
      var review = "";
      for (var i = 0; i < nodeCount; i++) {
        var node = root.childNodes.item(i);
        if (node.nodeType == Node.TEXT_NODE || 
            node.nodeType == Node.CDATA_SECTION_NODE) {
          review += node.data;
        } else {
          vxmllog("ignoring child " + i + " (" + node.nodeType + ")");
        }
      }            
    ]]></script>
    <prompt><value expr="review"/></prompt>
  </block>
</form>
</vxml>


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