开发者

iphone's nsxmlparser parsing RSS causes encoding problems

开发者 https://www.devze.com 2022-12-27 16:58 出处:网络
Im working on simle RSS reader. This reader loads data from internet via this code: NSXMLParser *rss = [[NSXMLParser alloc] initWithURL:[NSURL URLWithString:@\"http://twitter.com/statuses/user_timeli

Im working on simle RSS reader. This reader loads data from internet via this code:

NSXMLParser *rss = [[NSXMLParser alloc] initWithURL:[NSURL URLWithString:@"http://twitter.com/statuses/user_timeline/50405236.rss"]];

My proble开发者_如何转开发m is with encoding. RSS 2.0 file is supposed to be UTF8 encoded according to encoding attribute in XML file.

<?xml version="1.0" encoding="utf-8"?>

So when I download URLs content I get text truncated after first occurance of char with diacritics, example: ľ š č ť ž ý á í é, etc.

I tried to solve the problem by downloading URL as UTF8 string, I used this code:

NSString *rssXmlString = [NSString stringWithContentsOfURL: [NSURL URLWithString: @"http://www.macblog.sk/rss.xml"] encoding:NSUTF8StringEncoding error: nil]; 
NSData *rssXmlData = [rssXmlString dataUsingEncoding: NSUTF8StringEncoding];

Did not help. Thanx for your responses.


Check out MWFeedParser on GitHub, it's an open source RSS/Atom feed parser I've released and it makes reading and parsing web feeds extremely easy.

There's a simple demo app too which shows how easy it is to implement.

Hope this might be of some use!

0

精彩评论

暂无评论...
验证码 换一张
取 消