Escapes special XML characters in a string, so that the
string is safe to use with XML.

XMLFormat(String [, escapeNewSet]) → returns String

Argument Reference for the XMLFormat function


Required: Yes


Required: No

Examples sample code invoking the XMLFormat function

Basic XMLFormat() usage

In this example we demonstrate passing the invalid characters < and & into the XMLFormat() function to make them XML safe.

writeOutput( XMLFormat( '<node>Good &amp; Juicy</node>') );

Expected Result: &lt;node&gt;Good &amp;amp; Juicy&lt;/node&gt;

Advanced XMLFormat() usage

In this example we demonstrate parsing the cfdocs.org index page into XMLFormat() to make it safe for XML storage.

httpService = new http();
httpService.setMethod( 'get' );
httpService.setCharset( 'utf-8' );
httpService.setUrl( 'http://cfdocs.org/' );

xmlDoc = '<node>' & XMLFormat( httpService.send().getPrefix().fileContent ) & '</node>';

writeOutput( xmlDoc );
// NOTE: View results frame source in TryCF to see actual encoding

Expected Result: <node> [parsed HTML document] </node>

Fork me on GitHub