XMLSafe(str)
Last updated June 27, 2002
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"));
}
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