The following C/C++ example creates and appends a new text node to the root document element.
#import "msxml3.dll" using namespace MSXML2; inline void TESTHR( HRESULT _hr ) { if FAILED(_hr) throw(_hr); } void XMLDOMText() { try { IXMLDOMDocumentPtr docPtr; IXMLDOMNodePtr DOMNodePtr; IXMLDOMNamedNodeMapPtr DOMNamedNodeMapPtr; //init TESTHR(CoInitialize(NULL)); TESTHR(docPtr.CreateInstance("msxml2.domdocument")); // load a document _variant_t varXml("C:\book.xml"); _variant_t varOut((bool)TRUE); varOut = docPtr->load(varXml); if ((bool)varOut == FALSE) throw(0); DOMNodePtr = docPtr->createTextNode("Hello World"); 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(); }