View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > XmlFormat PreviousNext

XmlFormat

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

A copy of string that is safe to use with XML.

Extensibility functions, String functions, XML functions

XmlFormat(string)

cfxml, IsXmlDoc, XmlChildPos, XmlChildPos, XmlNew, XmlParse, XmlSearch, XmlTransform

ColdFusion MX: Added this function.

Parameter

Description

string

A string or a variable that contains one

The characters that this function escapes include the following:

<h3>XMLFormat</h3>
<p>This example shows how XMLFormat is used to escape special 
XML characters and make the use of XML with ColdFusion easy.</p> <XMP> <?xml version = "1.0"?> <cfoutput> <someXML> <someElement someAttribute = "#XMLFormat("'a quoted value'")#> #XMLFormat( "Body of element to be passed here.")# </someElement> </someXML> </cfoutput> </XMP>

Contents > CFML Reference > ColdFusion Functions > XmlFormat PreviousNext

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

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


jrunrandy said on Sep 24, 2003 at 6:16 AM :
In addition to the characters named above, the XmlFormat function also escapes hi-ascii characters(127 - 256).

This has been entered as doc bug 53457.
twillerror said on Oct 31, 2003 at 1:17 PM :
How does one reverse this. That is if I get a string that has &lt; &gt; etc, how do I get a string that contains <, >, etc.
Jon Briccetti said on Aug 20, 2004 at 1:06 PM :
check out cflib.org: http://www.cflib.org/udf.cfm?ID=800
hereticmessiah said on Jul 22, 2005 at 11:47 AM :
Annoyingly, this function screws with the whitespace in the text passed into it, compressing any whitespace into single space characters. This caught me out badly.

If this is the intended behaviour of the function, it ought to be noted here in the documentation. Otherwise, it's a bug that needs to be fixed.
No screen name said on Nov 1, 2005 at 4:27 AM :
Noted that XLMFormat() doesn't fix UK pound signs (£) properly, and causes IE to flip it's lid, even thought various XML testers say it's well formed code.

As a work around, I have used the following:

<cfset XMLText=ToString(myXML)>
<cfset XMLText = replace(XMLText, "UTF-8", "ISO-8859-1")>
<cfset XMLText = replace(XMLText,"£","&##x00A3;")>

This changes the document encoding, and replaces all pound signs with the relevent code.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/funca123.htm