将XML解析为NSDictionary [英] Parse XML to NSDictionary
问题描述
我正在使用AFNetworking 1.4.3从JSON检索NSDictionary
.现在,我必须使用新的AFNetworking 2.0来解析XML文件.例如:
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
}];
是否可以在不使用NSXMLParser
的情况下将XML文件直接映射到NSDictionary
?我正在寻找与2.0和XML输入等效的方法.
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.
推荐答案
是的,您可以避免使用nsxmlparser.直接使用libxml,这是为NSXMLParser提供动力的C api.
yes you can avoid nsxmlparser. use libxml directly which is the C api that powers the NSXMLParser.
苹果的不错的工作代码:
https://developer.apple.com/library/ios/samplecode /XMLPerformance/Introduction/Intro.html
不仅是libxml,而且还会显示libxml的用法
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
一篇不错的文章,解释了如何使用livxml:
http://www.cocoawithlove.com/2008 /10/using-libxml2-for-parsing-and-xpath.html
A nice article that explains how to use livxml:
http://www.cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html
如果您正在寻找现成的代码,那么nicklockwood的XMLDictionary类看起来非常合适:
https://github.com/nicklockwood/XMLDictionary
虽然它内部使用NSXMLParser
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
如果您有xml的XSD文件,请查看我的项目xsd2cocoa:
https://github.com/Daij-Djan/xsd2cocoa
完全没有NSXMLParser
if you have a XSD File for your xml, check out my project xsd2cocoa:
https://github.com/Daij-Djan/xsd2cocoa
No NSXMLParser at all
这篇关于将XML解析为NSDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!