Adrian Ciocălău
Adrian Ciocălău

Reputation: 361

ColdFusion EncodeForXML not working with UTF-8 characters

I am trying to create an XML file and I have a lot of special characters like ö, ä, etc. I am using EncodeForXML (previously used XMLFormat) but while on the browser it looks good, if I click view source and if I save the content as an XML file, those characters are converted to ö, ä etc

Here is an example:

<?xml version="1.0" encoding="utf-8" ?> 
    <kunde>
    <kdnr>118133</kdnr>
    <fullname>Conny R&#xf6;nnb&#xe4;ck</fullname>
    <delname1>Conny R&#xf6;nnb&#xe4;ck</delname1>
    <delname2></delname2>
    <delstreet>L&#xf6;ftets gr&#xe4;nd 1</delstreet>
    <delcountry>SE</delcountry>
    <delzipcode>90363</delzipcode>
    <deltown>Ume&#xe5;</deltown>
    <phone></phone>
    <mobile></mobile>
</kunde>

Any ideas how to make the EncodeForXML function to display correct special characters?

Upvotes: 0

Views: 311

Answers (1)

Adrian J. Moreno
Adrian J. Moreno

Reputation: 14859

What exactly are you trying to do with the XML? That's exactly what that function does. It encodes certain characters so they can be interpreted correctly by an XML parser.

<cfsavecontent variable="foo">
    <kunde>
        <kdnr>118133</kdnr>
        <fullname>Conny R&#xf6;nnb&#xe4;ck</fullname>
        <delname1>Conny R&#xf6;nnb&#xe4;ck</delname1>
        <delname2></delname2>
        <delstreet>L&#xf6;ftets gr&#xe4;nd 1</delstreet>
        <delcountry>SE</delcountry>
        <delzipcode>90363</delzipcode>
        <deltown>Ume&#xe5;</deltown>
        <phone></phone>
        <mobile></mobile>
    </kunde>
</cfsavecontent>

<cfdump var="#xmlParse(foo)#">

xmlParse()

Update: If you need to send the actual characters. then remove the encodeForXML() function and wrap each node's content with [CDATA][1].

The term CDATA, meaning character data, is used for distinct, but related, purposes in the markup languages SGML and XML. The term indicates that a certain portion of the document is general character data, rather than non-character data or character data with a more specific, limited structure.

<fullnane><![CDATA[#someQuery.fullname#]]></fullname>

Upvotes: 1

Related Questions