JavaScript method: XML.getNodeType()

This method evaluates an XML object and returns an integer representing the XML DOM type of the current element or attribute. You must use the other XML get methods to navigate through an XML document.

Syntax

XML.getNodeType();

Arguments

There are no arguments for this method.

Return values

A string or null.

The method returns an integer representing the XML DOM type of the current element or attribute or returns null if the method cannot determine the XML DOM type. See the W3C Web site for a complete listing of XML DOM node types by integer. It returns a TypeError if applied to anything other than an XML object. This limits this method to elements and attributes since the Service Manager XML object cannot represent element values as an XML object.

Example

This example displays the XML DOM types of the elements and attributes in an XML document.

This example requires the following sample data:

  • A local XML file (for example, C:\test.xml which contains <document><parent1>value1<child1 attribute1="a" /><child2 /></parent1><parent2><child3 /><child4 /></parent2></document>)
function visitElement( elem )
{
 print( "Element " + elem.getQualifiedName() + " is of type " + elem.getNodeType() );
 /* Print attributes for this element */
 var node = elem.getFirstAttribute();
 while( node != null )
 {
   var attrName  = node.getQualifiedName();
   var attrValue = node.getNodeValue();
   print( "Attribute " + attrName + "=" + attrValue + " and is of type " + node.getNodeType() );
   node = elem.getNextAttribute();
 }
 /* Print possible element value */
 var nodeValue = elem.getNodeValue();
 if ( typeof nodeValue == "string" && nodeValue.length > 0 )
 {
    print( "Element value is " + nodeValue + " and is of type " + elem.getNodeType() );
 }
 /* Now print child elements */
 var child = elem.getFirstChildElement();
 while( child != null )
 {
   var nodeName  = child.getNodeName();
   var nodeValue = child.getNodeValue();
   visitElement( child );
   child = child.getNextSiblingElement();
 }
}

var xmlObj =  new XML();
xmlObj.setContent( "c:\\test.xml", true );
visitElement( xmlObj.getDocumentElement() );