• Post Reply Bookmark Topic Watch Topic
  • New Topic

original purpose of "can not read remote XML correctly, due to encoding issue" thread  RSS feed

 
gang lee
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, since I can not get a solution of can not read remote XML correctly, due to encoding issue

let me tell my original purpose/problem:
I'd like to display weather info in my webpage.
so I get the information from googe: http://www.google.com/ig/api?weather=dalian&hl=zh-CN
using javascript at client side to parse the returned XML.

but there is a problem with IE: one has to enable "data source access across domain" in IE setting before being able to see the result.
I can not let every user to do that.

So i decided to create an JSP file which simple get and forward the XML to client side.(then there is no issue of ACROSS DOMAIN)

then come my problem: I can not properly get the weather info(ASCII part is ok, only the Chinese content not good) at serverside.

may anybody tell me how to do this?
[ July 20, 2008: Message edited by: gang lee ]
 
gang lee
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, guys.
very sad that nobody answered my questtion.

But, when I came to company and tried that code in Chinese version XP OS, then everything is ok.

So, I think the solution should be that:
I should set some fields in the HTTP request to:
http://www.google.com/ig/api?weather=dalian&hl=zh-CN
to let google think that I only prefer Chinese rather than Japanese.

does anyone know which filed(s) I should set and how?
Thanks a lot!
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before you do that, I suggest you try reading the InputStream using various Chinese encodings. I did some quick-and-dirty tests of the byte patterns and confirmed that the encoding is not UTF-8, but it could be EUC-CN. You could also try "GBK" and "GB18030".
 
gang lee
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moore, thanks a million!
I tried the endoing GBK and then EVERYTHING IS OK.

the code is:


but still one thing in my mind is that it seems the following code ever told me the encoding is MS932, when I was using a Japnese XP OS. I will check it again later...


[ July 21, 2008: Message edited by: gang lee ]
[ July 21, 2008: Message edited by: gang lee ]
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code only tells you which encoding the Reader tried to use. InputStreamReader has no way to know what the actual encoding of a file is; you have to tell it. Since you didn't specify one when you called the InputStreamReader constructor, it used the default encoding for your system, which is MS932.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!