943,594 Members | Top Members by Rank

Ad:
  • ColdFusion Discussion Thread
  • Marked Solved
  • Views: 6503
  • ColdFusion RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 1st, 2008
0

CF8 XML output problem with special character

Expand Post »
I am sending a query result (query in CF8; data in MS SQL Server 2005) to an XML output (using the <cfxml variable="outputname"> and <cfcontent type="text/xml"><cfoutput>#toString(outputname)#</cfoutput>
tags), using CF8. When the output (in SQL Server as nvarchar) contains special characters like "-40° to 70°C" the ° symbol causes the error;
******************************************
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
An invalid character was found in text content. Error processing resource 'http://localhost/ABSwwwroot/ArchboldData/toXML.c...

<instrumentation.InstrRange>-40

******************************************
How can I get this type of value to display properly?

Thanks!
kye
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kye is offline Offline
11 posts
since Sep 2007
Jul 2nd, 2008
0

Re: CF8 XML output problem with special character

Wrap your content inside a <![CDATA[ ]]> tag. XML will ignore any special characters inside.

XML Syntax (Toggle Plain Text)
  1. <instrumentation.InstrRange><![CDATA[-40° to 70°C]]></instrumentation.InstrRange>
Last edited by cmhampton; Jul 2nd, 2008 at 5:41 pm. Reason: added code example
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008
Jul 2nd, 2008
0

Re: CF8 XML output problem with special character

Thanks! That work great!!!
kye
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kye is offline Offline
11 posts
since Sep 2007
Jul 2nd, 2008
0

Re: CF8 XML output problem with special character

Guess I responded too quickly! Thought it was working - but it's NOT! Now (even with hard coding the value in) I am getting:
*********************************************************
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
An invalid character was found in text content. Error processing resource 'http://localhost/ABSwwwroot/ArchboldData/toXML.c...

<instrumentation.InstrRange><![CDATA[-40

*********************************************************

Seems ColdFusion puts XML output into XSL stylesheet format by default. I am trying to send this query result to a raw XML output page; NOT an HTML page (form) with XML source. Don't know if that makes a difference, but that's where I'm heading.
kye
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kye is offline Offline
11 posts
since Sep 2007
Jul 2nd, 2008
0

Re: CF8 XML output problem with special character

Strange. You may need to replace it with &deg;, still inside the cdata. I don't remember the ascii codes for the decimal character, but I'm sure that's pretty easy to find.
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008
Jul 2nd, 2008
0

Re: CF8 XML output problem with special character

Thanks again! I'll try it in the morning when my brain isn't quite so fried!
kye
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kye is offline Offline
11 posts
since Sep 2007
Jul 4th, 2008
0

Re: CF8 XML output problem with special character

Looks like I need another solution for this. Putting special characters in using the "&...." format is not a practical solution since clients will be entering the data. I need a solution that will pass WHATEVER wierd characters they may come up with thru - like one would THINK the CDATA tag would do; but it's not!!!
kye
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kye is offline Offline
11 posts
since Sep 2007
Jul 4th, 2008
0

Re: CF8 XML output problem with special character

I have a CFC method somewhere that replaces around 30 commonly used symbols. If I can find it, I'll post it.
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008
Jul 7th, 2008
0

Re: CF8 XML output problem with special character

Found it!

This will replace 67 special characters with their HTML equivalent. I've used this to generate RSS feeds before, so it should work just fine for you.

ColdFusion Syntax (Toggle Plain Text)
  1. <cffunction name="formatXML" access="public" returntype="string">
  2. <cfargument name="strString" required="yes" default="">
  3.  
  4. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("192", 16))#", "&fnof;", "all")>
  5. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("391", 16))#", "&Alpha;", "all")>
  6. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("392", 16))#", "&Beta;", "all")>
  7. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("393", 16))#", "&Gamma;", "all")>
  8. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("394", 16))#", "&Delta;", "all")>
  9. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("395", 16))#", "&Epsilon;", "all")>
  10. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("396", 16))#", "&Zeta;", "all")>
  11. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("397", 16))#", "&Eta;", "all")>
  12. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("398", 16))#", "&Theta;", "all")>
  13. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("399", 16))#", "&Iota;", "all")>
  14. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39A", 16))#", "&Kappa;", "all")>
  15. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39B", 16))#", "&Lambda;", "all")>
  16. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39C", 16))#", "&Mu;", "all")>
  17. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39D", 16))#", "&Nu;", "all")>
  18. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39E", 16))#", "&Xi;", "all")>
  19. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39F", 16))#", "&Omicron;", "all")>
  20. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A0", 16))#", "&Pi;", "all")>
  21. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A1", 16))#", "&Rho;", "all")>
  22. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A3", 16))#", "&Sigma;", "all")>
  23. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A4", 16))#", "&Tau;", "all")>
  24. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A5", 16))#", "&Upsilon;", "all")>
  25. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A6", 16))#", "&Phi;", "all")>
  26. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A7", 16))#", "&Chi;", "all")>
  27. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A8", 16))#", "&Psi;", "all")>
  28. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A9", 16))#", "&Omega;", "all")>
  29. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B1", 16))#", "&alpha;", "all")>
  30. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B2", 16))#", "&beta;", "all")>
  31. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B3", 16))#", "&gamma;", "all")>
  32. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B4", 16))#", "&delta;", "all")>
  33. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B5", 16))#", "&epsilon;", "all")>
  34. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B6", 16))#", "&zeta;", "all")>
  35. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B7", 16))#", "&eta;", "all")>
  36. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B8", 16))#", "&theta;", "all")>
  37. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B9", 16))#", "&iota;", "all")>
  38. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BA", 16))#", "&kappa;", "all")>
  39. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BB", 16))#", "&lambda;", "all")>
  40. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BC", 16))#", "&mu;", "all")>
  41. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BD", 16))#", "&nu;", "all")>
  42. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BE", 16))#", "&xi;", "all")>
  43. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BF", 16))#", "&omicron;", "all")>
  44. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C0", 16))#", "&pi;", "all")>
  45. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C1", 16))#", "&rho;", "all")>
  46. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C3", 16))#", "&sigma;", "all")>
  47. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C4", 16))#", "&tau;", "all")>
  48. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C5", 16))#", "&upsilon;", "all")>
  49. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C6", 16))#", "&phi;", "all")>
  50. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C7", 16))#", "&chi;", "all")>
  51. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C8", 16))#", "&psi;", "all")>
  52. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C9", 16))#", "&omega;", "all")>
  53. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3D1", 16))#", "&thetasym;", "all")>
  54. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3D2", 16))#", "&upsih;", "all")>
  55. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3D6", 16))#", "&piv;", "all")>
  56. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2022", 16))#", "&bull;", "all")>
  57. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2026", 16))#", "&hellip;", "all")>
  58. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2032", 16))#", "&prime;", "all")>
  59. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2033", 16))#", "&Prime;", "all")>
  60. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("203E", 16))#", "&oline;", "all")>
  61. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2044", 16))#", "&frasl;", "all")>
  62. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2118", 16))#", "&weierp;", "all")>
  63. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2111", 16))#", "&image;", "all")>
  64. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("211C", 16))#", "&real;", "all")>
  65. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2122", 16))#", "&trade;", "all")>
  66. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2135", 16))#", "&alefsym;", "all")>
  67. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2200", 16))#", "&forall;", "all")>
  68. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2202", 16))#", "&part;", "all")>
  69. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2203", 16))#", "&exist;", "all")>
  70. <cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2205", 16))#", "&empty;", "all")>
  71.  
  72. </cffunction>
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008
Jul 8th, 2008
0

Re: CF8 XML output problem with special character

OK, this is great! Can you tell me where I would find other symbols/codes (ex. &omega or &Deg) for other symbols (like the ± for instance)? I've tried looking this up on the web and can't seem to find this info.
kye
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kye is offline Offline
11 posts
since Sep 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ColdFusion Forum Timeline: Image upload to MySQL using CF & DW CS3???
Next Thread in ColdFusion Forum Timeline: Unable to capture XML Response





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC