CF8 XML output problem with special character

Thread Solved

Join Date: Sep 2007
Posts: 11
Reputation: kye is an unknown quantity at this point 
Solved Threads: 1
kye kye is offline Offline
Newbie Poster

CF8 XML output problem with special character

 
0
  #1
Jul 1st, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 72
Reputation: cmhampton is an unknown quantity at this point 
Solved Threads: 10
cmhampton's Avatar
cmhampton cmhampton is offline Offline
Junior Poster in Training

Re: CF8 XML output problem with special character

 
0
  #2
Jul 2nd, 2008
Wrap your content inside a <![CDATA[ ]]> tag. XML will ignore any special characters inside.

  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
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: kye is an unknown quantity at this point 
Solved Threads: 1
kye kye is offline Offline
Newbie Poster

Re: CF8 XML output problem with special character

 
0
  #3
Jul 2nd, 2008
Thanks! That work great!!!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: kye is an unknown quantity at this point 
Solved Threads: 1
kye kye is offline Offline
Newbie Poster

Re: CF8 XML output problem with special character

 
0
  #4
Jul 2nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 72
Reputation: cmhampton is an unknown quantity at this point 
Solved Threads: 10
cmhampton's Avatar
cmhampton cmhampton is offline Offline
Junior Poster in Training

Re: CF8 XML output problem with special character

 
0
  #5
Jul 2nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: kye is an unknown quantity at this point 
Solved Threads: 1
kye kye is offline Offline
Newbie Poster

Re: CF8 XML output problem with special character

 
0
  #6
Jul 2nd, 2008
Thanks again! I'll try it in the morning when my brain isn't quite so fried!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: kye is an unknown quantity at this point 
Solved Threads: 1
kye kye is offline Offline
Newbie Poster

Re: CF8 XML output problem with special character

 
0
  #7
Jul 4th, 2008
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!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 72
Reputation: cmhampton is an unknown quantity at this point 
Solved Threads: 10
cmhampton's Avatar
cmhampton cmhampton is offline Offline
Junior Poster in Training

Re: CF8 XML output problem with special character

 
0
  #8
Jul 4th, 2008
I have a CFC method somewhere that replaces around 30 commonly used symbols. If I can find it, I'll post it.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 72
Reputation: cmhampton is an unknown quantity at this point 
Solved Threads: 10
cmhampton's Avatar
cmhampton cmhampton is offline Offline
Junior Poster in Training

Re: CF8 XML output problem with special character

 
0
  #9
Jul 7th, 2008
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.

  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>
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: kye is an unknown quantity at this point 
Solved Threads: 1
kye kye is offline Offline
Newbie Poster

Re: CF8 XML output problem with special character

 
0
  #10
Jul 8th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the ColdFusion Forum
Thread Tools Search this Thread



Tag cloud for ColdFusion
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC