The Comment object represents the contents of a comment, i.e., all the characters that
appear between the '<!--' and '-->'.
In the following 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.
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>
Code (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
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.
denotes a Microsoft extension to the W3C DOM.
PROPERTIES
attributes Property
This is a read-only property that returns an
NamedNodeMap for nodes that can have
attributes.
Syntax: Node.attributes
baseName Property
This is a read-only property that returns the base name for a node.
Syntax: Node.baseName
childNodes Property
This is a read-only property containing a node list of all children for those elements that
can have them.
Syntax: Node.childNodes
data Property
This property contains the data for this node, depending on node type.
Syntax: CharacterData.data
dataType Property
This is a read-only property that specifies the data type for the node.
Syntax: Node.dataType
definition Property
This property returns the definition of the node in the DTD or schema.
Syntax: Node.definition
firstChild Property
This is a read-only property that returns the first child node of a node. If there is none,
it returns null.
Syntax: Node.firstChild
lastChild Property
This is a read-only property that returns the last child node of a node. If there is none,
it returns null.
Syntax: Node.lastChild