Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I`m trying to use google`s unofficial weather API,,
You can find it here
http://www.google.com/ig/api?weather=amman[^]

i use the doc.load(urlgoeshere) function and its working fine..
but when i add a query to he api`s url (to request an arabic langauge response)
(http://www.google.com/ig/api?weather=amman&hl=ar[^] )
the doc.load function wont load and gives the following error msg

"System.Xml.XmlException: Invalid character in the given encoding"

i think the (&) in the url is what causes the error.. any help would be appreciated.
Posted
Updated 14-Feb-12 2:04am
v2

You probably need to use the encoding of the xml file returned by the weather API. Have a look at the link:
http://support.microsoft.com/kb/308061/en-us[^]

Good luck!
 
Share this answer
 
The exception happens later on, when the response from Google is to be loaded by the XmlDocument. And Google uses a different encoding for the English and Arabic response, resp.: ISO 8859-1 for English, and Windows-1256 for Arabic.
Following code works on my computer with both requests:
C#
XmlDocument doc = new XmlDocument();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/ig/api?weather=amman&hl=ar");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(resStream);
doc.Load(reader);
 
Share this answer
 
Comments
WaleedMuh 14-Feb-12 10:03am    
Many thanks for your response..
using the code you sent the error does not appear any more
but now i get question marks instead of the letters.. it seems like an encoding problem.. do you know how to fix it.. thanks in advance.
Bernhard Hiller 15-Feb-12 2:52am    
Make sure that you use a proper encoding (unicode, windows-1256) when you display the results.
Without any code/hints from you (where do you get the question marks?), I cannot tell the position where your problem arises.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900