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.
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);#comment
8
longest employed staff firstIn 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.
Syntax: characterData.data
This property contains the data for this node, depending on node type.
Syntax: characterData.length
This property is read-only and contains the length of the data string in characters.
Syntax: characterData.appendData(data)
This method appends the specified string to existing string data.
Syntax: characterData.deleteData(offset, count)
This method is used to remove the specified range of characters from string data.
Syntax: characterData.insertData(offset, data)
This method is used to insert a string at the specified offset.
Syntax: characterData.replaceData(offset, count, data)
This method replaces the characters from the specified offset with the supplied string data.
Syntax: characterData.substringData(offset, count)
This method returns a substring consisting of the specified range of characters.