METHOD:  Document::createComment

Document.createComment(data)

The createComment method creates a Comment object whose value is the text supplied as the argument. Creating an instance of this object does not automatically include it in the XML Document tree, and so its parentNode property is set to null.

The following example creates a Comment consisting of a last-updated statement, and appends it to the children of the document's root element. It then displays the new node's type, name and value.

Code (JavaScript):
var xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("quotations.xml");

var root = xml_doc.documentElement;
var comment = xml_doc.createComment("last updated January 1999");
root.appendChild (comment);

var curr_node = root.lastChild;
document.write (curr_node.nodeType);
document.write ("<br>" + curr_node.nodeName);
document.write ("<br>" + curr_node.nodeValue);

Output:
8
#comment
last updated January 1999

The value '8' returned for the node's type indicates that it is a Comment object (see the list of node types).



Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information