0

I am trying to get a response xml which has special characters in it. This is failing in IE but in Mozilla it is working fine. Pls let me know how to fix this.

Here's the code:

request.setCharacterEncoding("UTF-8");
response.setContentType("text/xml; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<xml><valid><![CDATA[2189971_Bright Starts bath time foam ©®!@& toys each]]></valid><productid>123</productid></xml>");
sth
  • 222,467
  • 53
  • 283
  • 367
hari
  • 11
  • 2

2 Answers2

0

Try adding the encoding in the XML itself:

response.getWriter().write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><valid><![CDATA[2189971_Bright Starts bath time foam ©®!@& toys each]]></valid><productid>123</productid></root>");
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
0

Most likely your XML is invalid - you are specifying UTF8 encoding in the XML but writing code probably does not output UTF8. Check out what browser receives with some HTTP watcher (likle Fiddler) to make sure response is properly UTF8 encoded (the characters you are having problem with must be encode as their are above ASCII range).

Not sure what language/framework you are using, but setting encoding on request and writing to response looks suspicious.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • I don't know as framework you are using does not feel familiar, but if goolge fails for you try Bing http://www.bing.com/search?q=request.setCharacterEncoding brings following link that may be of interest to you http://stackoverflow.com/questions/3278900/httpservletrequest-setcharacterencoding-seems-to-do-nothing – Alexei Levenkov Apr 28 '11 at 16:23