Reputation: 2252
I was using AFNetworking 1.4.3 to retrieve NSDictionary
from JSON. Now I have to use new AFNetworking 2.0 to parse XML file. For example:
[self getPath:path parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
// Mapping XML to my own MR_object
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// Error handling here
}];
Is it possible to map XML file directly to NSDictionary
without using NSXMLParser
? I am looking for equvalent for this for in 2.0 and for XML input.
Upvotes: 2
Views: 6203
Reputation: 50089
yes you can avoid nsxmlparser. use libxml directly which is the C api that powers the NSXMLParser.
Nice working code from apple:
https://developer.apple.com/library/ios/samplecode/XMLPerformance/Introduction/Intro.html
Not ONLY libxml but also show the usage of libxml
A nice article that explains how to use livxml:
http://www.cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html
if you are looking for ready-made code then nicklockwood's XMLDictionary class looks like a very good fit:
https://github.com/nicklockwood/XMLDictionary
It Internally uses NSXMLParser though
if you have a XSD File for your xml, check out my project xsd2cocoa:
https://github.com/Daij-Djan/xsd2cocoa
No NSXMLParser at all
Upvotes: 3