Open alfaro28 opened 10 years ago
This started happening in iOS 8 and I'm not sure why. There was another bug in early versions of iOS 8 that passing NSData from a data task to the XMLParser would crash; the only way to get around that was to re-encode the data several times before passing it to the parser. They seem to have fixed that problem, but this issue with Extra content...
still crops up occasionally. I'm probably not going make AFNetworking a dependency for this library, so it'd be worth filing a bug report with Apple. From my testing I've seen this behavior when parsing XML even outside of this library, so I don't believe it's specific to the library's business logic.
Any ideas on why this bug is not happening with AFNetworking?
Not sure. I haven't used AFNetworking much since NSURLSession came out, but it probably wouldn't be hard to figure out what they're doing differently than a basic setup like this if you wanted to take a look.
I don't use BNRSSFeedParser, but I've been experiencing NSXMLParserErrorMessage=Extra content at the end of the document
on a simple document fetched with NSURLSession and parsed with https://github.com/tadija/AEXML which is a simple wrapper around NSXMLParser.
I looped the parser and it seems that it does work in 2nd or so attempt on the same XML data, which, along with @farski's comments above, makes me believe that this is a bug with NSXMLParser.
Strangely enough, re-encoding the data (as suggested by @farski) still works. It fixed the erroneous parsing behaviour for me.
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)!
let reEncodedData = dataString.dataUsingEncoding(NSUTF8StringEncoding)
Regarding why it does not happen when using AFNetworking, I wonder if it uses NSXMLParser any differently? Or maybe the data provided is re-encoded here as well?
Thnx Gurpartap. Encoding and Reencoding solved this error for me.
When I try to parse a feed with white spaces at the end of the file it fails with
NSXMLParserErrorMessage=Extra content at the end of the document
the weird thing is sometimes it works but most of the time it fails, even weirder is that if I replace the network code with AFNetworking it will always work, any idea on why is this happening? It may be inconvenient to "tie" this project with AFNetworking but maybe it can incorporate the logic that is preventing the error in AFNetworking.In the meanwhile replacing
with something like
fixes the issue, you can try to reproduce it with the following feed
http://kite-ideas.com/feed.XML