Represents the content of an XML comment.
The following script example creates a new IXMLDOMComment (comment) and appends it as the last child node of DOMDocument.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var root;
var comment;
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode <> 0) {
var myErr = xmlDoc.parseError;
alert("You have error " + myErr.reason);
} else {
root = xmlDoc.documentElement;
comment = xmlDoc.createComment("Hello World!");
root.appendChild(comment);
alert(root.xml);
}
The following Microsoft® Visual Basic® example creates a new IXMLDOMComment (comment) and appends it as the last child node of DOMDocument.
Dim xmlDoc As New Msxml2.DOMDocument50
Dim root As IXMLDOMElement
Dim comment As IXMLDOMComment
xmlDoc.async = False
xmlDoc.Load ("books.xml")
If (xmlDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xmlDoc.parseError
MsgBox("You have error " & myErr.reason)
Else
Set root = xmlDoc.documentElement
Set comment = xmlDoc.createComment("Hello World!")
root.appendChild comment
MsgBox (root.xml)
End If
The following sample creates and appends a new XMLDOMComment node to the root document element.
#import "msxml5.dll"
using namespace MSXML2;
inline void TESTHR( HRESULT _hr )
{ if FAILED(_hr) throw(_hr); }
void XMLDOMCommentSample()
{
try {
IXMLDOMDocumentPtr docPtr;
IXMLDOMNodePtr DOMNodePtr;
//init
TESTHR(CoInitialize(NULL));
TESTHR(docPtr.CreateInstance("Msxml2.DOMDocument.5.0"));
// load a document
_variant_t varXml("C:\\book.xml");
_variant_t varOut((bool)TRUE);
varOut = docPtr->load(varXml);
if ((bool)varOut == FALSE)
throw(0);
MessageBox(NULL, _bstr_t(docPtr->xml), _T("Original Document"), MB_OK);
DOMNodePtr = docPtr->createComment("This is a comment node");
docPtr->documentElement->appendChild(DOMNodePtr);
MessageBox(NULL, _bstr_t(docPtr->xml), _T("New Document"), MB_OK);
} catch(...)
{
MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);
}
CoUninitialize();
}
The content refers to all characters between the start <!-- and end --> tags.
IXMLDOMComment has no unique members and exposes the same members IXMLDOMCharacterData.
MSXML 2.0 and later
Implementation: msxml4.dll, msxml2.lib
Header and IDL files: msxml2.h, msxml2.idl
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button
in the upper-left corner of the page.
IXMLDOMCharacterData | IXMLDOMComment Members | IXMLDOMElement