xmlHasChild

Checks if the XML document object has a child node

xmlHasChild(xmlObject [, childName]) → returns boolean

This function requires Adobe ColdFusion 2023 and up.  Not supported on Lucee, etc.

Argument Reference

xmlObject xml
Required

The XML document object to be checked for child nodes

childName string

The name of the child node to check if it exists. If not provided, the root is checked.

Examples
Sample code invoking the xmlHasChild function

Checks the existence of children for two separate nodes in a simple XML document

xmlData = xmlParse('<root><item id="1">Item 1</item><item id="2">Item 2</item><item id="3">Item 3</item></root>');
writeOutput(xmlHasChild(xmlData, "root"));
writeOutput(" " & xmlHasChild(xmlData, "item"));

Expected Result: YES NO

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub