ukwebguy
asked on
How to produce a UTF-8 XML document using Classic ASP
I am trying to send an XML document in response to requests from 2 different clients (using classic ASP). Currently I'm extracting the information from a database and building the XML document as a string, then using Response.Write to send it back. (See below)
Using encoding='ISO-8859-1' it worked well, the £ (pound) symbol displayed but the Euro symbol and some apostrophes did not render correctly, so I amended it to use encoding='windows-1252' which worked for all symbols with one client but not with the other, who has requested that I use UTF-8 encoding.
Simply changing the encoding method to encoding='UTF-8' in the document header has not worked as my client is getting an error message like this...
Invalid byte 1 of 1-byte UTF-8 sequence.
This tells me that I need to actually encode the data in some way rather than just changing to header. Can anyone tell me how I proceed from here, please?
This may be quite simple if you know how (isn't it always like that?) but I've upped the points because I'm under pressure here, to produce a solution ASAP.
XMLResponse = "<?xml version='1.0' encoding='UTF-8' ?>"
XMLResponse = XMLResponse & "<comp>"
XMLResponse = XMLResponse & "<status>Success</status>"
XMLResponse = XMLResponse & "<id>" & id & "</id>"
XMLResponse = XMLResponse & "<header><![CDATA[" & header & "]]></header>"
XMLResponse = XMLResponse & "<question><![CDATA[" & question & "]]></question>"
XMLResponse = XMLResponse & "<answersnumber>" & i & "</answersnumber>"
XMLResponse = XMLResponse & "<specialterms><![CDATA[" & SpecialRules & "]]></specialterms>"
XMLResponse = XMLResponse & "<starts>" & Year(starts) & "-" & PadZero(Month(starts)) & "-" & PadZero(Day(starts)) & "</starts>"
XMLResponse = XMLResponse & "<closes>" & Year(closes) & "-" & PadZero(Month(closes)) & "-" & PadZero(Day(closes)) & "</closes>"
XMLResponse = XMLResponse & "</comp>"
Response.Write XMLResponse
Using encoding='ISO-8859-1' it worked well, the £ (pound) symbol displayed but the Euro symbol and some apostrophes did not render correctly, so I amended it to use encoding='windows-1252' which worked for all symbols with one client but not with the other, who has requested that I use UTF-8 encoding.
Simply changing the encoding method to encoding='UTF-8' in the document header has not worked as my client is getting an error message like this...
Invalid byte 1 of 1-byte UTF-8 sequence.
This tells me that I need to actually encode the data in some way rather than just changing to header. Can anyone tell me how I proceed from here, please?
This may be quite simple if you know how (isn't it always like that?) but I've upped the points because I'm under pressure here, to produce a solution ASAP.
XMLResponse = "<?xml version='1.0' encoding='UTF-8' ?>"
XMLResponse = XMLResponse & "<comp>"
XMLResponse = XMLResponse & "<status>Success</status>"
XMLResponse = XMLResponse & "<id>" & id & "</id>"
XMLResponse = XMLResponse & "<header><![CDATA[" & header & "]]></header>"
XMLResponse = XMLResponse & "<question><![CDATA[" & question & "]]></question>"
XMLResponse = XMLResponse & "<answersnumber>" & i & "</answersnumber>"
XMLResponse = XMLResponse & "<specialterms><![CDATA[" & SpecialRules & "]]></specialterms>"
XMLResponse = XMLResponse & "<starts>" & Year(starts) & "-" & PadZero(Month(starts)) & "-" & PadZero(Day(starts)) & "</starts>"
XMLResponse = XMLResponse & "<closes>" & Year(closes) & "-" & PadZero(Month(closes)) & "-" & PadZero(Day(closes)) & "</closes>"
XMLResponse = XMLResponse & "</comp>"
Response.Write XMLResponse
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Didn'#t work completely for me
ASKER