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

encodeForXML Argument Reference


The string to encode.

canonicalize boolean
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.



Version 4.5+ Lucee does not support the canonicalize argument.

Examples sample code invoking the encodeForXML function

Encodes the ampersand into an XML entity.

encodeForXML("Fred & Ted")

Expected Result: Fred & Ted

Fork me on GitHub