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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson