Reputation: 1069
If I give non-xml string (or junk xml) to NSXMLParser it will result in crash. How validate xml before passing it to NSXMLParser?
Upvotes: 0
Views: 1760
Reputation: 14113
You need to implement following delegate methods for ParseOperation delegate :
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
Upvotes: 0
Reputation: 8163
it will not crash, if NSXMLParser
finds an error, it will let you know through its delegate, either by invoking parser:validationErrorOccurred:
or – parser:parseErrorOccurred:
. You can use the - (NSError *)parserError
in NSXMLParser
to determine the error wich caused the parsing to terminate.
I hope it helps you!
Cheers
Upvotes: 3
Reputation: 31722
Having a validating parser in place can reduce the required code to parse XML a lot, Check the the blog post IPHONE: LIBXML2 & RELAX NG VALIDATION
http://blog.mro.name/2010/05/iphone-libxml2-relax-ng-validation/
Upvotes: 0