IXMLDOMNode

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

IXMLDOMNode

Extends the core node with support for data types, namespaces, document type definitions (DTDs), and schemas.

[Script]

Example

The following script example creates an IXMLDOMNode, currNode, and displays its XML.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var currNode;
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode <> 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   currNode = xmlDoc.documentElement.childNodes.item(1);
   alert(currNode.xml);
}
[Visual Basic]

Example

The following Microsoft® Visual Basic® example creates an IXMLDOMNode, currNode, and displays its XML.

Dim xmlDoc As New Msxml2.DOMDocument50
Dim currNode As IXMLDOMNode
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 currNode = xmlDoc.documentElement.childNodes.Item(1)
   MsgBox currNode.xml
End If
[C/C++]

Example

The following C/C++ example creates and appends a new node to the document root.

#include <tchar.h>
#import "msxml5.dll"
using namespace MSXML2;

inline void TESTHR( HRESULT _hr ) 
   { if FAILED(_hr) throw(_hr); }

void XMLDOMNodeSample()
{
   try {
      IXMLDOMDocumentPtr docPtr;
      IXMLDOMNodePtr DOMNodePtr;

      //init
      TESTHR(CoInitialize(NULL)); 
      TESTHR(docPtr.CreateInstance("Msxml2.DOMDocument.5.0"));
      
      VARIANT vtTemp;

      vtTemp.vt=VT_I2;
            vtTemp.iVal = 1; //NODE_ELEMENT
      // load a document
      _variant_t varXml("c:\\Temp\\books.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->createNode(vtTemp, "VIDEOS", "");
      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();
}
int main()
{
   XMLDOMNodeSample();
   return 0;
}

Versioning

MSXML 2.0 and later

Requirements

Implementation: msxml5.dll, msxml2.lib

[C/C++]

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 Language Filter in the upper-left corner of the page.

See Also

IXMLDOMNode Members | IXMLDOMNodeList