XmlGetNodeType

Description

Determines the type of an XML document object node.

Returns

A string identifying the XML node type. The following values are valid:

ATTRIBUTE_NODE

CDATA_SECTION_NODE

COMMENT_NODE

DOCUMENT_FRAGMENT_NODE

DOCUMENT_NODE

DOCUMENT_TYPE_NODE

ELEMENT_NODE

ENTITY_NODE

ENTITY_REFERENCE_NODE

NOTATION_NODE

PROCESSING_INSTRUCTION_NODE

TEXT_NODE

If the argument is not a document object node, the function generates an error.

Category

XML functions

Function syntax

XmlGetNodeType(xmlNode)

See also

IsXmlAttribute, IsXmlDoc, IsXmlElem, IsXmlNode, IsXmlRoot, XmlChildPos, XmlValidate; Using XML and WDDX in the Developing ColdFusion Applications

History

ColdFusion MX 7: Added this function.

Parameters

Parameter

Description

xmlNode

An XML DOM object node

Usage

The XmlGetNodeType function can determine the types of the nodes returned by the XmlSearch function, or the types of the entries in an element’s XmlNodes array.

Example

The following example checks the node types of various parts of an XML document object:

<!--- Create an XML document object ---> 
<cfxml variable="xmlobject"> 
<?xml version="1.0" encoding="UTF-8"?> 
<order id="4323251"> 
    <customer firstname="Philip" lastname="Cramer" accountNum="21"/> 
    <items> 
        <item id="43"> 
            <!-- This item is coded to show several node types --> 
            <![CDATA["Our Best" hammer & chisel set!!!]]> Imported from France 
            <quantity>1</quantity> 
            <unitprice>15.95</unitprice> 
        </item> 
    </items> 
</order> 
</cfxml> 
 
<!--- Display the node types ---> 
<cfoutput> 
<h3>Node Types</h3> 
xmlobject: #XMLGetNodeType(xmlobject)#<br> 
xmlobject.order: #XMLGetNodeType(xmlobject.order)#<br> 
<br> 
Now check the types of all the nodes in the xmlobject.order.items.item  
element's XmlNodes array.<br> 
    Note the many apparently empty Text nodes generated by whitespace characters in the XML text source.<br><br> 
<cfset descnodes=xmlobject.order.items.item.XmlNodes> 
<cfloop from="1" to="#ArrayLen(descnodes)#" index="i"> 
    #i# Node type is: #XMLGetNodeType(descnodes[i])#<br> 
    #i# Node name is: #descnodes[i].XmlName#<br> 
    <cfif (descnodes[#i#].XmlValue NEQ "")> 
        #i# Node value is: #descnodes[i].XmlValue#<br> 
    </cfif> 
    <br> 
</cfloop> 
</cfoutput>