다음을 통해 공유


IXMLDOMComment

 

Represents the content of an XML comment.

Jscript Example

The following JScript example creates a new IXMLDOMComment (comment) and appends it as the last child node of DOMDocument.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");  
var root;  
var comment;  
xmlDoc.async = false;  
xmlDoc.loadXML("<root/>");  
if (xmlDoc.parseError.errorCode != 0) {  
   var myErr = xmlDoc.parseError;  
   WScript.Echo("You have error " + myErr.reason);  
} else {  
   root = xmlDoc.documentElement;  
   comment = xmlDoc.createComment("Hello World!");  
   root.appendChild(comment);  
   WScript.Echo(root.xml);  
}  
  

Output

<root><!--Hello World!></root>  

C++ Example

The following C++ sample creates and appends a new XMLDOMComment node to the root document element.

#include “msxml6.h”  
  
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.3.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();  
}  
  

Remarks

The content refers to all characters between the start (<!--) and end (>) tags.

IXMLDOMComment has no unique members and exposes the same members IXMLDOMCharacterData.

Requirements

Implementation:

msxml3.dll, msxml2.lib (MSXML 3.0)

msxml6.dll, msxml6.lib (MSXML 6.0)

Header and IDL files (C/C++): msxml2.h, msxml2.idl, msxml6.h, msxml6.idl

Versioning

Implemented in: MSXML 3.0, MSXML 6.0

See Also

IXMLDOMCharacterData
IXMLDOMComment Members
IXMLDOMElement