If you are like me, who loves to use RaptureXML for parsing XML documents, and to use AFNetworking
when playing with REST APIs, then this post is for you.
AFRaptureXMLRequestOperation*operation=[AFRaptureXMLRequestOperationXMLParserRequestOperationWithRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:@"http://legalindexes.indoff.com/sitemap.xml"]]success:^(NSURLRequest*request,NSHTTPURLResponse*response,RXMLElement*XMLElement){// Do something with XMLElement }failure:^(NSURLRequest*request,NSHTTPURLResponse*response,NSError*error,RXMLElement*XMLElement){// Handle the error}];[operationstart];
If subclassing AFHTTPClient then we just need to use registerHTTPOperationClass to register it with AFRaptureXMLRequestOperation
12345678910111213
-(id)initWithBaseURL:(NSURL*)url{self=[superinitWithBaseURL:url];if(!self){returnnil;}[selfregisterHTTPOperationClass:[AFRaptureXMLRequestOperationclass]];// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1[selfsetDefaultHeader:@"Accept"value:@"text/xml;level=1,application/xml;level=2"];returnself;}
I created this extension several months ago, but recently updated it to use ARC and included some
minor tweaks based on some official extensions.
Feel free to play around with it, fork it and send any pull requests.