encodeForXMLAttribute

Encodes a string that can be used as an XML attribute.

encodeForXMLAttribute(String inputString, boolean canonicalize); → returns Encoded XML string.

Argument Reference for the encodeForXMLAttribute function

inputString

Required: Yes
The string to encode.

canonicalize

Required: No
If set to true, canonicalization happens before encoding. If set to false, the given input string will just be encoded. The default value for canonicalize is false. When this parameter is not specified, canonicalization will not happen. By default, when canonicalization is performed, both mixed and multiple encodings will be allowed. To use any other combinations you should canonicalize using canonicalize method and then do encoding.

Examples sample code invoking the encodeForXMLAttribute function


Tag Syntax

<!---- Prints ,.-_ ----> 
 <cfset x=encodeForXMLAttribute(",.-_")> 
 <cfoutput>#x#</cfoutput> 
 <!---- Prints &#x3c;script&#x3e; ----> 
 <cfset x=encodeForXMLAttribute("<script>")> 
 <cfoutput>#x#</cfoutput> 
 <!---- Prints &#x21;&#x40;&#x24;&#x25;&#x28;&#x29;&#x3d;&#x2b;&#x7b;&#x7d;&#x5b;&#x5d; ----> 
 <cfset x=encodeForXMLAttribute("!@$%()=+{}[]")> 
 <cfoutput>#x#</cfoutput> 

Fork me on GitHub