XML DOM » Objects » Comment

The Comment object represents the contents of a comment, i.e., all the characters that appear between the '<!--' and '-->'.

A Comment is also a Node object, and so inherits various properties and methods from it. For details of the values returned by the nodeName, nodeType and nodeValue properties for a Comment, see the Node object.

Examples

Code:
XML:

<staff>
   <!-- longest employed staff first -->
   <employee ssn="123456" pay="3">
      <f_name>John</f_name>
      <l_name>Sullivan</l_name>
   </employee>
   <employee ssn="987654" pay="2">
      <f_name>Mary</f_name>
      <l_name>Lopez</l_name>
   </employee>
</staff>

JavaScript:

xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("staff.xml");

elem = xml_doc.documentElement.firstChild;
document.write(elem.nodeName);
document.write("<br>" + elem.nodeType);
document.write("<br>" + elem.nodeValue);
Output:
#comment
8
longest employed staff first
Explanation:

In this example we use the 'staff.xml' file which has one comment as the first child node of the root element. The code displays the nodeName, nodeType and nodeValue properties for this Comment.

Language(s): JavaScript XML

Properties

data

Syntax: characterData.data

This property contains the data for this node, depending on node type.

length

Syntax: characterData.length

This property is read-only and contains the length of the data string in characters.

Methods

appendData

Syntax: characterData.appendData(data)

This method appends the specified string to existing string data.

deleteData

Syntax: characterData.deleteData(offset, count)

This method is used to remove the specified range of characters from string data.

insertData

Syntax: characterData.insertData(offset, data)

This method is used to insert a string at the specified offset.

replaceData

Syntax: characterData.replaceData(offset, count, data)

This method replaces the characters from the specified offset with the supplied string data.

substringData

Syntax: characterData.substringData(offset, count)

This method returns a substring consisting of the specified range of characters.

See Also: