开发者

NSXMLParserPrematureDocumentEndError = 5 // The document ended unexpectedly

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:

NSXMLP开发者_运维问答arserPrematureDocumentEndError = 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.


try changing from

NSURL *xmlUrl = [NSURL fileURLWithPath:@"http://172.16.202.155/results.xml"];

to

NSURL *xmlUrl = [NSURL URLWithString:@"http://172.16.202.155/results.xml"];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜