读取ISO-8859-1 RSS订阅C#WP7 [英] Reading iso-8859-1 rss feed C# WP7
问题描述
我想读它使用ISO-8859-1编码的RSS源。
I'm trying to read a rss feed which uses the iso-8859-1 encoding.
我可以得到所有的元素精,问题是,当我把它在一个TextBlock它不会显示所有字符。我不知道我做错了。我已经尝试了一些解决方案,我在谷歌找到,但这并没有为我工作。我必须失去了一些东西..这也是我第一次真正具有比UTF-16以外的任何工作。我从来没有过任何东西转换。
I can get all elements fine, the problem is when I put it in a textblock it will not show all characters. I'm not sure what i'm doing wrong. i've tried a few solutions I found on google but this didn't work for me. I must be missing something.. It's also the first time I really work with anything other than utf-16. I never had to convert anything before.
该应用程序的工作原理如下我downloadstring异步(Web客户端)。所以,当那个叫我得到包含完整的RSS源的字符串。
The app works as follows I downloadstring async(WebClient). So when that is called I get a string containing the complete rss feed.
我试图获取字节,则encoding.convert ..但我必须失去了一些东西。
I have tried getting the bytes, then encoding.convert.. But I must be missing something.
像这是一个样本
WebClient RSS = new WebClient();
RSS.Encoding = Encoding.GetEncoding("ISO-8859-1");
RSS.DownloadStringCompleted += new DownloadStringCompletedEventHandler(RSS_DSC);
RSS.DownloadStringAsync(new Uri("some rss feed"));
public void RSS_DSC(object sender, DownloadStringCompletedEventArgs args)
{
_xml = XElement.Parse(args.Result);
foreach(XElement item in _xml.Elements("channel").Elements("item"))
{
feeditem.title = item.Element("title").Value;
// + all other items
}
}
我试过这个藏汉
private void RSS_ORC(object sender, OpenReadCompletedEventArgs args)
{
Encoding e = Encoding.GetEncoding("ISO-8859-1");
Stream ez = args.Result;
StreamReader rdr = new StreamReader(ez, e);
XElement _xml = _xml = XElement.Parse(rdr.ReadToEnd());
feedlist = new List<Code.NewsItem>();
XNamespace dc = "http://purl.org/dc/elements/1.1/";
foreach (XElement item in _xml.Elements("channel").Elements("item"))
{
Code.NewsItem feeditem = new Code.NewsItem();
feeditem.title = item.Element("title").Value;
feeditem.description = item.Element("description").Value;
feeditem.pubdate = item.Element("pubDate").Value;
feeditem.author = item.Element(dc + "creator").Value;
feedlist.Add(feeditem);
}
listBox1.ItemsSource = feedlist;
}
虽然标题中包含未显示任何良好的字符。如..我可以得到编码部分工作。而不是让这些字符:用一个问号,问号或烧灼方方
Though titles contain characters that are not displayed well either. Like.. I can get the encoding to partially work. Instead of having these characters: the square with a question mark, a question mark or the singe square.
不要误会我的意思,我在这个总的初学者。但是已经在网上公布了解决方案并没有解决这个问题,我
Don't get me wrong I'm a total beginner on this. But the solutions that has been posted on the web do not solve it for me.
请注意,我删除了编码部分,因为它不工作:/
。如果有人能帮助我,这将是惊人的。
Note that I removed the encoding part because it wasn't working :/ If someone would be able to help me that would be amazing.
推荐答案
您可以通过设置编码指定编码的前的调用 client.DownloadStringAsync
:
You can specify an encoding by setting encoding before calling client.DownloadStringAsync
:
webClient.Encoding = Encoding.GetEncoding("iso-8859-1")
在您的代码示例不创建在XML文档的任何地方。有一些代码丢失?你应该像初始化:
In your code sample you do not create the XML doc anywhere. Are some code missing? You should initialize it with something like:
var xml = XDocument.Load((string)args.Result);
这篇关于读取ISO-8859-1 RSS订阅C#WP7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!