CFLib.org – Common Function Library Project

XMLUnFormat(string)

Last updated November 15, 2002
Download UDF

author

Kreig Zimmerman                                   Kreig Zimmerman

Version: 1 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 1 time(s). Average Rating: 5.0

Description:
This is a simple UDF which does the exact opposite of CFMX's XmlFormat() function. Specifically, it replaces the following five characters in XML-escaped data with their normal equivalents: > with > < with < ' with ' " with " & with &

Return Values:
Returns a string.

Example:

<cfscript>
XmlSafe="&quot;That&apos;s a very safe string &amp; &lt;TAG&gt; you&apos;re it!!!&quot;";
XmlUnsafe=XmlUnformat(XmlSafe);
WriteOutput(htmlCodeFormat(XmlUnsafe));
</cfscript>

Parameters:

Name Description Required
string String to format. Yes

Full UDF Source:

<cfscript>
/**
* UN-escapes the five forbidden characters in XML data.
*
* @param string      String to format. (Required)
* @return Returns a string.
* @author Kreig Zimmerman (kkz@foureyes.com)
* @version 1, November 15, 2002
*/

function XMLUnFormat(string) {
    var resultString=string;
    resultString=ReplaceNoCase(resultString,"&apos;","'","ALL");
    resultString=ReplaceNoCase(resultString,"&quot;","""","ALL");
    resultString=ReplaceNoCase(resultString,"&lt;","<","ALL");
    resultString=ReplaceNoCase(resultString,"&gt;",">","ALL");
    resultString=ReplaceNoCase(resultString,"&amp;","&","ALL");
    return resultString;
}
</cfscript>

Search CFLib.org


Latest Additions

Raymond Camden Raymond Camden added
romanToDecimal
3 day(s) ago

Joe Rinehart Joe Rinehart added
directoryCopy
4 day(s) ago

Marcos Placona Marcos Placona added
arrayGroupsOf
4 day(s) ago

Mosh Teitelbaum Mosh Teitelbaum added
formatListAsSeri...
25 day(s) ago

Top Rated

Nick Giovanni                                     UniqueValueList
Rated 5.0, 5 time(s)

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Bobby Hartsfield                                  randStr
Rated 5.0, 3 time(s)

Rob Brooks-Bilson                                 FolderSize
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson