XmlFormat

Description

Escapes special XML characters in a string so that the string can be used as text in XML.

Returns

A copy of the string parameter that is safe to use as text in XML.

Category

String functions, XML functions

Function syntax

XmlFormat(string)

See also

cfxml, XmlNew, XmlParse, XmlValidate; Using XML and WDDX in ColdFusion MX Developer's Guide

History

ColdFusion MX: Added this function.

Parameters

Parameter Description

string

A string or a variable that contains one

Usage

This function escapes characters as follows:

Text character Escaped representation

Greater than symbol (>)

>

Less than symbol (<)

&lt;

Single-quotation mark (')

&apos;

Double-quotation mark (")

&quot;

Ampersand symbol (&)

&amp;

Carriage return (but not line feed)

Removed from the text.

High ASCII characters in the range 128-255.

Replaced by unicode escape sequence; for example, É (capital E with an Acute symbol) is replaced by &#xc9;.

Example

The following example shows how XmlFormat escapes special XML characters. Use the View Source command in the browser to see the results. ColdFusion interprets the "" in the second text string as representing a single-quotation mark in text before it applies the XmlFormat function.

<?xml version = "1.0"?> 
<cfoutput>
<someXML>
   <someElement someAttribute="#XmlFormat("'a quoted value'")#"> 
      #XmlFormat("Body of element with <, >, "" and & goes here.")#
   </someElement>
</someXML>
</cfoutput>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7