The following method and properties can be used to get the following information about a node.
If the node has any children.
The namespace to which the node belongs.
The name of the node.
The type of the node.
The type of the node.
If the node has been parsed.
If the node is explicitly specified in the XML file or implied within the document type definition (DTD) or XML Schema.
The string representation of the 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