encodeForXMLAttribute

Encodes a string for safe output within an XML attribute. Use encodeForXML when outputting a variable inside a XML tag body.

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

encodeForXMLAttribute Argument Reference

inputString
Required

The string to encode.

canonicalize
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 encodeForXMLAttribute function


Simple encodeForXMLAttribute Example

Encodes the single quote into an XML entity.

encodeForXMLAttribute("It's for use in attribute values")

Expected Result: It's for use in attribute values


Fork me on GitHub