I am using an RSS feed as a data source. I’ve adjusted how I retrive the data to use the WebClient.DownloadStringAsync method. Before I was using XmlReader.Create method. I’m then using the results as a data source to bind to a TextBlock in WPF.
Since I made the change when I display my results all the special encoded characters are appearing as odd characters. Would love some help making sure I keep the proper encoding so that my display values don’t have the odd characters.
// WebClient code...
private void GetFeed(int i)
{
Uri _feedUri = new Uri(_feedList[i]);
webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(stringStringCompletedEvent);
webClient.DownloadStringAsync(_feedUri, _feedTokenList[i]);
}
private void stringStringCompletedEvent(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
string xmlString = e.Result;
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
doc.Save(@"C:\CashierData\msnbc-top.xml");
}
}
Here is my previous code using XmlReader to download and parse the feed.
XmlReader reader = XmlReader.Create(feed, settings);
I suspect the problem is that the web server isn’t specifying the content encoding correctly.
You could use
DownloadDataAsyncinstead, and then use(where
datais the byte array). Then the XML parser will get to auto-detect the XML encoding from the binary data, instead of trusting the web server to know the right encoding.