Encodes a string for safe use within an XML tag body. Use encodeForXMLAttribute for variables output inside an XML attribute value.

encodeForXML(inputString , [canonicalize]); → returns string

Argument Reference for the encodeForXML function


Required: Yes
The string to encode.


Required: No
Default: false
When true the canonicalize function is called before encoding the input. If set to false, the given input string will just be encoded, both mixed and multiple encodings will be allowed. Values:
  • true
  • false



Version 4.5+ Lucee does not support the canonicalize argument.

Examples sample code invoking the encodeForXML function

Simple encodeForXML Example

Encodes the ampersand into an XML entity.

encodeForXML("Fred & Ted")

Expected Result: Fred & Ted

Fork me on GitHub