Comment Object
Last Updated: 08-25-2005
Represents an XML comment 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 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.

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="*"?>
  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.

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"

    <data name="dom" src="comment.xml"/>
      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 +=;
        } else {
          vxmllog("ignoring child " + i + " (" + node.nodeType + ")");
    <prompt><value expr="review"/></prompt>

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