解析 XML 页面时 NSXMLParserErrorDomain 错误 5
我正在尝试用 Objective-C 解析 XML 页面。错误的全文是:
Error Domain=NSXMLParserErrorDomain Code=5“操作无法完成。(NSXMLParserErrorDomain 错误 5。)”
我正在尝试像这样解析页面:
NSURL *xmlUrl = [NSURL fileURLWithPath:@"xmlpage"];
NSXMLParser *xmlDoc = [[NSXMLParser alloc] initWithContentsOfURL: xmlUrl];
XMLParser *parser = [[XMLParser alloc]init];
希望得到任何帮助,谢谢。
I am trying to parse an XML page in Objective-C. The full text of the error is:
Error Domain=NSXMLParserErrorDomain Code=5 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 5.)"
I am attempting to parse the page like so:
NSURL *xmlUrl = [NSURL fileURLWithPath:@"xmlpage"];
NSXMLParser *xmlDoc = [[NSXMLParser alloc] initWithContentsOfURL: xmlUrl];
XMLParser *parser = [[XMLParser alloc]init];
Would appreciate any help, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不清楚你在做什么。您创建一个 NSXMLParser,但将其称为文档。但事实并非如此。然后您创建一个 XMLParser,它是一个 ?也许是一些第三方API?
我面前没有代码,但基本上您需要设置一个 NSXMLParser 委托,它可以在解析器读取 XML 元素时接收它们。然后您需要告诉解析器开始处理 XML。
另一件需要注意的事情是确认该 URL 实际上是源自 XML,而不是其他内容。
It's not clear to me what you are doing. You create a NSXMLParser, but call it a doc. Which it isn't. You then create a XMLParser which is a ? Some third party API perhaps ?
I don't have my code in front of me, but basically you need to setup a NSXMLParser delegate which can receive the XML element as the parser reads them. You then need to tell the parser to start processing the XML.
Another thing to look at is to confirm that the URL is actually sourcing XML and not some other content.