NSXMLParserPrematureDocumentEndError = 5 // 文档意外结束
我一直在浏览 Stackoverflow 和其他论坛中的问题,并尝试了几种建议的解决方案,但没有任何效果。我正在使用 Xcode 4.0.1 和 iPhone 4.3 模拟器。
我收到的错误:
NSXMLParserPrematureDocumentEndError = 5 // 文档意外结束。
这是 XML 文件:
<?xml version="1.0" encoding="utf-8" ?>
<errorDetails>
<errorCode>15</errorCode>
<errorText>The very special error</errorText>
</errorDetails>
这是调用代码:
NSURL *xmlUrl = [NSURL fileURLWithPath:@"http://172.16.202.155/results.xml"];
NSXMLParser *xmlDoc = [[NSXMLParser alloc] initWithContentsOfURL: xmlUrl];
XMLParser *parser = [[XMLParser alloc]init];
[xmlDoc setDelegate: parser];
[xmlDoc setShouldProcessNamespaces:NO];
[xmlDoc setShouldReportNamespacePrefixes:NO];
[xmlDoc setShouldResolveExternalEntities:NO];
[xmlDoc parse];
if ([xmlDoc parserError]){
NSLog(@"%@",[xmlDoc parserError]);
}
else NSLog(@"Parsing done!");
链接有效,在 webView 中可见。
这些在 XMLparser.m 中实现,但似乎从未需要它们。
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
谢谢你帮助我。
I've been browsing through the questions in Stackoverflow and other forums and tried several suggested solutions but nothing works. I'm using Xcode 4.0.1 with iPhone 4.3 simulator.
The error Im receiving:
NSXMLParserPrematureDocumentEndError = 5 // The document ended unexpectedly.
This is the XML file:
<?xml version="1.0" encoding="utf-8" ?>
<errorDetails>
<errorCode>15</errorCode>
<errorText>The very special error</errorText>
</errorDetails>
This is the calling code:
NSURL *xmlUrl = [NSURL fileURLWithPath:@"http://172.16.202.155/results.xml"];
NSXMLParser *xmlDoc = [[NSXMLParser alloc] initWithContentsOfURL: xmlUrl];
XMLParser *parser = [[XMLParser alloc]init];
[xmlDoc setDelegate: parser];
[xmlDoc setShouldProcessNamespaces:NO];
[xmlDoc setShouldReportNamespacePrefixes:NO];
[xmlDoc setShouldResolveExternalEntities:NO];
[xmlDoc parse];
if ([xmlDoc parserError]){
NSLog(@"%@",[xmlDoc parserError]);
}
else NSLog(@"Parsing done!");
The link works, it is visible in webView.
These are implemented in XMLparser.m but it seems like they are never called for.
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
Thank you for helping me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试从 更改
为
try changing from
to