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!

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

<instrumentation.InstrRange><![CDATA[-40° to 70°C]]></instrumentation.InstrRange>

Thanks! That work great!!!

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.

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.

Thanks again! I'll try it in the morning when my brain isn't quite so fried!

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!!!

I have a CFC method somewhere that replaces around 30 commonly used symbols. If I can find it, I'll post it.

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.

<cffunction name="formatXML" access="public" returntype="string">
		<cfargument name="strString" required="yes" default="">
		
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("192", 16))#", "&fnof;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("391", 16))#", "&Alpha;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("392", 16))#", "&Beta;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("393", 16))#", "&Gamma;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("394", 16))#", "&Delta;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("395", 16))#", "&Epsilon;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("396", 16))#", "&Zeta;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("397", 16))#", "&Eta;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("398", 16))#", "&Theta;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("399", 16))#", "&Iota;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39A", 16))#", "&Kappa;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39B", 16))#", "&Lambda;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39C", 16))#", "&Mu;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39D", 16))#", "&Nu;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39E", 16))#", "&Xi;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("39F", 16))#", "&Omicron;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A0", 16))#", "&Pi;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A1", 16))#", "&Rho;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A3", 16))#", "&Sigma;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A4", 16))#", "&Tau;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A5", 16))#", "&Upsilon;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A6", 16))#", "&Phi;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A7", 16))#", "&Chi;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A8", 16))#", "&Psi;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3A9", 16))#", "&Omega;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B1", 16))#", "&alpha;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B2", 16))#", "&beta;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B3", 16))#", "&gamma;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B4", 16))#", "&delta;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B5", 16))#", "&epsilon;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B6", 16))#", "&zeta;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B7", 16))#", "&eta;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B8", 16))#", "&theta;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3B9", 16))#", "&iota;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BA", 16))#", "&kappa;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BB", 16))#", "&lambda;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BC", 16))#", "&mu;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BD", 16))#", "&nu;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BE", 16))#", "&xi;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3BF", 16))#", "&omicron;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C0", 16))#", "&pi;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C1", 16))#", "&rho;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C3", 16))#", "&sigma;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C4", 16))#", "&tau;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C5", 16))#", "&upsilon;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C6", 16))#", "&phi;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C7", 16))#", "&chi;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C8", 16))#", "&psi;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3C9", 16))#", "&omega;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3D1", 16))#", "&thetasym;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3D2", 16))#", "&upsih;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("3D6", 16))#", "&piv;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2022", 16))#", "&bull;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2026", 16))#", "&hellip;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2032", 16))#", "&prime;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2033", 16))#", "&Prime;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("203E", 16))#", "&oline;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2044", 16))#", "&frasl;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2118", 16))#", "&weierp;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2111", 16))#", "&image;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("211C", 16))#", "&real;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2122", 16))#", "&trade;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2135", 16))#", "&alefsym;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2200", 16))#", "&forall;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2202", 16))#", "&part;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2203", 16))#", "&exist;", "all")>
		<cfset strString = ReplaceNoCase(strString, "#chr(inputbasen("2205", 16))#", "&empty;", "all")>
		
	</cffunction>

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.

http://www.paulschou.com/tools/iso8859.html has a pretty comprehensive list. It's a lot to wade through, but you'll probably never need to look anywhere else.

BTW, is this for an engineering publication? Just out of curiosity...

http://www.paulschou.com/tools/iso8859.html has a pretty comprehensive list. It's a lot to wade through, but you'll probably never need to look anywhere else.

BTW, is this for an engineering publication? Just out of curiosity...

Thanks for all the help. We found another way to work it. By inserting charset=utf-8 into <cfcontent type="text/xml; charset=utf-8"><cfoutput>#toString(projectXml)#</cfoutput></cfcontent>. We are able to send all charactors to the XML output so far.

This work is for a Eco/Biological Research Org. http://www.archbold-station.org/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.