encodeForXML

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

inputString

Required: Yes
The string to encode.

canonicalize

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

Compatibility

Lucee:

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