User Guide Cancel

IsXML

 

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

Decision functionsXML functions

Function syntax

IsXML(value,parserOptions)
IsXML(value,parserOptions)
IsXML(value,parserOptions)

See also

IsXmlAttributeIsXmlDocIsXmlElemIsXmlNodeIsXmlRootXmlParseXmlValidateUsing XML and WDDX in the Developing ColdFusion Applications

History

ColdFusion (2018 release): Introduced named parameters.

ColdFusion MX 7: Added this function.

Parameters

Parameter

Description

value

parserOptions

A string containing the XML document text

XML parsing options

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.

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>
<!--- 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>
<!--- 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>

Get help faster and easier

New user?