Checking for proper xml before parsing in NSXMLParser
If I give non-xml string (or junk xml) to NSXMLP开发者_如何转开发arser it will result in crash. How validate xml before passing it to NSXMLParser?
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
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/
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
加载中,请稍侯......
精彩评论