I am trying to make a basic webclient call to get an xml stream for a post tracking app for WP7. It does work and I do get the xml but the problem is as I am living in Sweden we have special characters as å ö ä etc. and for these characters I only get a box with questionmark inside.
The xml file I want to get looks like this:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>
<pactrack version="2.0" date="Sat Jan 14 18:29:26 CET 2012" size="2125" lang="SE">
<header>
<noofparcelentries>1</noofparcelentries>
...
So the encoding is ISO-8859-1 and i guess that is my problem. Been trying to read around here on the forum for a solution and some say that the format is supported while some not: Reading iso-8859-1 rss feed C# WP7
I been trying to add differnt encodings to the client but nothing seems to help, my xml is missing the special symbols always. There is however a strange behavior that kinda freaks me out, if I add a wrong tracking number, and instead of numbers put in special characters I can suddenly read some of the special characters,the xml I get from the server is an error message containing the tracking number, see below, but the xml definition is the same.
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<pactrack version="2.0" date="Sat Jan 14 18:34:43 CET 2012" size="389" lang="SE" >
<header>
<noofparcelentries>1</noofparcelentries>
<noofuniqueparcels>1</noofuniqueparcels>
</header>
<body>
<parcel id="8538öööåå54248SE"> //I can read this road of xml suddenly
<customerref></customerref>
<internalstatus>0</internalstatus>
Anyone have any ideas? I am a beginner and totally lost by this problem so any help would be greatly appreciated! Is there any difference in the first xml and the second? It seems to me maybe I cant see special charters that are nested in nodes, can that be the problem?
WebClient client = new WebClient();
public MainPage()
{
InitializeComponent();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
if (e.UserState as string == "mobiforge")
{
txtStatus.Text = e.BytesReceived.ToString() + "bytes received.";
}
}
public void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null && !e.Cancelled)
{
MessageBox.Show(e.Result);
}
}
private void btnDownload_Click(object sender, RoutedEventArgs e)
{
client.DownloadStringAsync(new Uri("http://server.logistik.posten.se/servlet/PacTrack?lang=SE&kolliid=85380954248SE"), "posten");
}