Gathering Information About a Node

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Developer's Guide

Gathering Information About a Node

The following method and properties can be used to get the following information about a node.

The following sample code tests the nodeTypeString property to see if the node is of type "element". If the node is of type "element", the string representation of the node is loaded into a new document object through the loadXML method, creating a document fragment.

if (xmlNode.nodeTypeString == "element")
   XMLDoc.loadXML(xmlNode.xml)
   if (xmlDoc.parseError.errorCode <> 0) {
         var myErr = xmlDoc.parseError;
      alert("You have error " + myErr.reason);
   }

You can use the following code if you prefer to work with the numeric representation.

if (xmlNode.nodeType == 1)
   XMLDoc.loadXML(xmlNode.xml)
If (xmlDoc.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox("You have error " & myErr.reason)
Emd IF

You can get the name of a node by checking the nodeName property.

currentNodeName=xmlNode.nodeName

You can use the following code to find nodes without child nodes and retrieve their content as a string.

if (xmlNode.hasChildren == false)
  currentNodeContent=xmlNode.xml

You can use the following code to limit the nodes processed to nodes from specific namespaces.

if (xmlNode.namespaceURI == "http://www.examples.microsof.com/catalog")
  'catalog-specific processing here