使用 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/