开发者

Checking for proper xml before parsing in NSXMLParser

开发者 https://www.devze.com 2023-02-28 19:22 出处:网络
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

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  
0

精彩评论

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