Reputation: 699
I'm trying to import a list of leagues from this XML file into a table.
I'm able to find the elements I require but where the league name has a special/foreign character in it then it is not displaying it correctly.
For example, in the XML file there is the following node:
<trans-unit resname="global.leagueFull.2014.league1005">
<source>Colombia Finalización</source>
</trans-unit>
But when I run my code the output for this league is Colombia Finalización.
My code is as follows:
<cfscript>
xmlContent = xmlParse("http://www.easports.com/iframe/fut/bundles/futweb/web/flash/xml/localization/messages.en_GB.xml");
subSet = xmlSearch(xmlContent,'/xliff/file/body/trans-unit/');
</cfscript>
<cfloop from="1" to="#ArrayLen(subset)#" index="i">
<cfset resName = subSet[i].xmlAttributes.resName />
<cfif Find("global.leagueFull.2014.league",resName)>
<cfset leagueName = subSet[i].xmlChildren[1].xmlText />
<cfset leagueID = ListLast(resName,".") />
<cfset leagueID = Mid(leagueID,7,15) />
<cfoutput>#leagueName#<br /></cfoutput>
</cfif>
</cfloop>
Does anyone know what might be causing the loss of these characters, and if there is a way to prevent or indeed remedy it?
Thanks
Upvotes: 2
Views: 285
Reputation: 338208
If you see something like Finalización
that invariably means that an UTF-8 source has been interpreted as a legacy (i.e. a one-byte-per-character) encoding.
Congratulations, you just found a bug in ColdFusion. (As per Adam Cameron's hint in the comments, this is Bug #3183072 which has been fixed as of CF 11.)
Try this work-around instead:
<cfhttp url="http://www.easports.com/iframe/fut/bundles/futweb/web/flash/xml/localization/messages.en_GB.xml">
<cfif ListFirst(cfhttp.statusCode, " ") eq "200">
<cfset xmlContent = XmlParse(cfhttp.FileContent)>
<cfset xPath = "/xliff/file/body/trans-unit[starts-with(@resname, 'global.leagueFull.2014.league')]">
<cfset subSet = XmlSearch(xmlContent, xPath)>
<cfloop array="#subSet#" index="transUnit">
<cfset leagueName = transUnit.source>
<cfset leagueID = Mid(ListLast(transUnit.XmlAttributes.resName, "."), 7, 15)>
<cfoutput>#HTMLEditFormat(leagueName)#<br></cfoutput>
</cfloop>
<cfelse>
Error fetching file. (<cfoutput>#cfhttp.StatusCode#</cfoutput>)
</cfif>
Note that I've used XPath's starts-with()
to replace your <cfif>
. That's more efficient and concise.
Upvotes: 5