Whatever message this page gives is out now! Go check it out!

IsXML

Last update:
May 18, 2026

Description

Determines whether a string is well-formed XML text.

Returns

True, if the function parameter is a string that contains well-formed XML text; False, otherwise.

Category

Function syntax

IsXML(value,parserOptions)

See also

IsXmlAttribute IsXmlDoc IsXmlElem IsXmlNode IsXmlRoot XmlParse XmlValidate Using XML and WDDX  in the Developing ColdFusion Applications

History

ColdFusion (2018 release): Introduced named parameters.
ColdFusion MX 7: Added this function.

Parameters

ParameterDescription
value
parserOptions
A string containing the XML document text
A struct that controls XML parser behavior for the current invocation.
Supported keys include:
  • ALLOWDOCTYPEDECLARATION: Boolean. Default: false
  • ALLOWEXTERNALENTITIES: Boolean. Default: false
  • ENTITYEXPANSIONLIMIT: Numeric

Usage

This function determines whether text is well-formed XML, that is, it conforms to all XML syntax and structuring rules. The string does not have to be a complete XML document. The function does not validate against a Document Type Definition (DTD) or XML Schema.
Starting in ColdFusion (2025.0.08), IsXML() returns false for input that contains a <!DOCTYPE ...> declaration unless you explicitly pass parserOptions.ALLOWDOCTYPEDECLARATION = true.Use this option only when the XML comes from a trusted source and a DOCTYPE declaration is expected. For untrusted XML, keep the default behavior.
<!--- XML containing DOCTYPE is rejected by default --->
<cfset isOk = IsXML(myXmlString)>

<!--- Explicit opt-in for trusted XML --->
<cfset opts = { ALLOWDOCTYPEDECLARATION = true }>
<cfset isOk = IsXML(myXmlString, opts)>
IMPORTANT
IsXML() is often used as a pre-check before parsing. Keep ALLOWDOCTYPEDECLARATION=false unless the XML source is trusted.

Example

The following example creates two strings, and tests whether they are well-formed XML text:
<!--- A well formed XML string ---> 
<cfset xmlString1='<order id="4323251"> 
<customer firstname="Philip" lastname="Cramer" accountNum="21"/> 
<items> 
<item id="43"> 
<quantity>1</quantity> 
<unitprice>15.95</unitprice> 
</item> 
</items> 
</order>' 


<!--- An invalid XML string, missing the </item> close tag ---> 
<cfset xmlString2='<order id="4323251"> 
<customer firstname="Philip" lastname="Cramer" accountNum="21"/> 
<items> 
<item id="43"> 
<quantity>1</quantity> 
<unitprice>15.95</unitprice> 
</items> 
</order>' 


<!--- Test the strings to see if they are well formed XML ---> 
<cfoutput> 
xmlString1 contains the following text:<br><br> 
#HTMLCodeFormat(xmlstring1)# 
Is it well formed XML text? #IsXML(xmlString1)#<br><br> 
<hr> 
xmlString2 contains the following text:<br><br> 
#HTMLCodeFormat(xmlstring2)# 
Is it well formed XML text? #IsXML(xmlString2)# 
</cfoutput>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page