CFLib.org – Common Function Library Project

IsXML(data)

Last updated August 28, 2003

author

Ben Forta

Version: 1 | Requires: CF6 | Library: DataManipulationLib

Description:
Checks to see if a string is valid XML.

Return Values:
Returns a boolean.

Example:

<cfsavecontent variable="packet">
<foo></foo>
</cfsavecontent>

<cfoutput>
Is packet XML? #isXML(packet)#<br>
Is "jedi" a packet? #isXML("jedi")#
</cfoutput>

Parameters:

Name Description Required
data String to check. Yes

Full UDF Source:

<!---
 Checks to see if a string is valid XML.
 
 @param data      String to check. (Required)
 @return Returns a boolean. 
 @author Ben Forta (ben@forta.com) 
 @version 1, August 28, 2003 
--->
<cffunction name="isXML" returnType="boolean" output="no">
   <cfargument name="data" type="string" required="yes">

   <!--- try catch block --->
   <cftry>
      <!--- try to parse the data as xml --->
      <cfset xmlparse(data)>
      <!--- if xmlparse() fails, it is not xml --->
      <cfcatch type="any">
         <cfreturn false>
      </cfcatch>
   </cftry>

   <cfreturn true>
   
</cffunction>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson