CFLib.org – Common Function Library Project

XMLSafe(str)

Last updated June 27, 2002

author

Mark Knox

Version: 1 | Requires: CF5 | Library: StrLib

Description:
XMLFormat escapes special XML characters so that you can put arbitrary strings safely into XML. However, it does not filter non-printable characters which can cause some XML Parser Engines to crash.

Return Values:
Returns a string.

Example:

<!--- Build the string inserting a non-printable
      character.  CHR(146) will typically show
      up as an apostrophe in most editors and
      data-dump programs --->

<cfset myvar = "Joe" & Chr(146) & "s Cafe'">

<!--- Output the string to view --->
Value before the function: <cfoutput>#myvar#</cfoutput><br>

<!--- Now view the output with the function --->
Value after the function: <cfoutput>#XMLSafe(myvar)#</cfoutput>

Parameters:

Name Description Required
str The string to format. Yes

Full UDF Source:

/**
 * Extends XMLFormat to include stripping non-printable characters.
 * 
 * @param str 	 The string to format. (Required)
 * @return Returns a string. 
 * @author Mark Knox (mark@3pss.com) 
 * @version 1, June 27, 2002 
 */
function XMLSafe(str) {
  return XMLFormat(REReplace(str, "[^[:print:]]", "", "ALL"));
}
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