User Guide
448 Chapter 2: ColdFusion Tags
To change the declaration to specify another encoding, use the Replace function. To specify the
encoding of the text that is returned to a browser or other application, use the
cfcontent tag.
The following example illustrates this process:
<cfprocessingdirective suppresswhitespace="Yes">
<cfcontent type="text/xml; charset=utf-16">
<cfxml variable="xmlobject">
<breakfast_menu>
<food>
<name quantity="50">Belgian Waffles</name>
<description>Our famous Belgian Waffles</description>
</food>
</breakfast_menu>
</cfxml>
<!--- <cfdump var="#xmlobject#">--->
<cfset myvar=toString(xmlobject)>
<cfset mynewvar=replace(myvar, "UTF-8", "utf-16")>
<!---<cfdump var="#mynewvar#">--->
<cfoutput>#mynewvar#</cfoutput>
</cfprocessingdirective>
The cfprocessingdirective tag prevents ColdFusion from putting white space characters in
front of the XML declaration.
Example
This following example creates a document object whose root element is MyDoc. The object
includes text that displays the value of the ColdFusion variable testVar. The code creates four
nested child elements, which are generated by an indexed
cfloop tag. The cfdump tag displays
the XML document object.
<cfset testVar = True>
<cfxml variable="MyDoc">
<?xml version='1.0' encoding='utf-8' ?>
<MyDoc>
<cfif testVar IS True>
<cfoutput>The value of testVar is True.</cfoutput>
<cfelse>
<cfoutput>The value of testVar is False.</cfoutput>
</cfif>
<cfloop index = "LoopCount" from = "1" to = "4">
<childNode>
This is Child node <cfoutput>#LoopCount#.</cfoutput>
</childNode>
</cfloop>
</MyDoc>
</cfxml>
<cfdump var=#MyDoc#>