ios - 使用 nsxmlparser 解析 rss 提要时如何忽略非法字符?

标签 ios rss nsxmlparser

使用 NSXMLParser 时(间接通过 Michael Waterfalls MWFeedParser 库)
并解析以下 RSS 提要:

http://qdb.us/qdb.xml?action=latest

NSURL *feedURL = [NSURL URLWithString:@"http://qdb.us/qdb.xml?action=random"];
self.feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
self.feedParser.delegate = self;
self.feedParser.feedParseType = ParseTypeFull; // Parse feed info and all items
self.feedParser.connectionType = ConnectionTypeAsynchronously;
[self.feedParser parse];

我收到了一个格式无效的 xml 文档,该文档似乎是提要中的非法字符。

http://validator.w3.org/check?uri=http%3A%2F%2Fqdb.us%2Fqdb.xml%3Faction%3Dlatest&charset=utf-8&doctype=Inline&group=0&user-agent=W3C_Validator%2F1.1

我尝试将文档编码从 ISO-8859-1 更改为 UTF-8,但问题仍然存在。

如何识别非法字符,然后如何使它在遇到这些非法字符时解析 RSS 提要不会失败?

引用资料:(我已经调查过的链接)

HTML character decoding in Objective-C / Cocoa Touch

https://stackoverflow.com/users/106244/michael-waterfall

最佳答案

我不知道如何忽略非法字符,但是您可能会考虑在解析之前进行一些正则表达式更正以删除它们,但我建议使用 nsxmlparser 的 killxml instand,这对于非法字符可能没问题,here是“如何为您的 iPhone 项目选择最佳 XML 解析器”

关于ios - 使用 nsxmlparser 解析 rss 提要时如何忽略非法字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10186283/

相关文章:

java - 用 Java 解析 HTML 以创建 XML

iOS - 从 ViewController 调用 App Delegate 方法

iphone - NSDateFormatter 无法正常工作?

javascript - 如何将此 RSS 提要放入 jQuery ListView 中?

ios - NSXMLParser 到达 xsi :nil 时出现错误 201

iphone - 属性文本中的 NSXMLParser 引号

ios - NSURLConnection sendAsynchronousRequest 从不释放内存

objective-c - 关于objective-c中 "strong"属性的问题

java - 使用 Java 和 Sax 解析某些 RSS 提要时遇到问题

javascript - 从 RSS/Atom 提要中提取图像