Parse Error on iPhone: NSXMLParserPrematureDocumentEndError

I have an app which fetches/parses XML and I keep getting a parse error at random. The parse error has an error code of 5, which corresponds to NSXMLParserPrematureDocumentEndError. This seems to be the error for when the device doesn't have a connection and tries to fetch a URL... except sometimes I get it even when the device Does have a connection. It happens more often on Edge, but can happen anytime.

Does anyone have an idea as to what the problem might be? Or a possible solution? I can't find any evidence of other people having this problem, which leads me to believe I'm doing something wrong :P. I based my XML code off of Seismic.

Mike O.

Posted on Aug 11, 2008 3:27 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 23, 2008 3:40 PM

I had similar problems when I initialized the parser with a URL.
To debug that (and see what it was trying to parse), I fetched the XML as part of a NSURLRequest and then calling [NSURLConnection sendSynchronousRequest, then initializing the parser with the returned data like this: [[NSXMLParser alloc] initWithData:receivedData];

If the parsing still gives me an error, slip that data into an NSString before calling parse so I can take a look at it.

I haven't had those errors since changing it to fetch the xml first, then initialize a parser with the data rather than initializing the parser with initwithContentsOfURL.

Brian
3 replies
Question marked as Top-ranking reply

Oct 23, 2008 3:40 PM in response to ikon_zero

I had similar problems when I initialized the parser with a URL.
To debug that (and see what it was trying to parse), I fetched the XML as part of a NSURLRequest and then calling [NSURLConnection sendSynchronousRequest, then initializing the parser with the returned data like this: [[NSXMLParser alloc] initWithData:receivedData];

If the parsing still gives me an error, slip that data into an NSString before calling parse so I can take a look at it.

I haven't had those errors since changing it to fetch the xml first, then initialize a parser with the data rather than initializing the parser with initwithContentsOfURL.

Brian

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Parse Error on iPhone: NSXMLParserPrematureDocumentEndError

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.