Whatever message this page gives is out now! Go check it out!
IsXML(value,parserOptions)| Parameter | Description |
value parserOptions | A string containing the XML document text A struct that controls XML parser behavior for the current invocation. Supported keys include:
|
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)>IsXML() is often used as a pre-check before parsing. Keep ALLOWDOCTYPEDECLARATION=false unless the XML source is trusted.<!--- 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>