2014-10-10 33 views
0

我知道关于NSXMLParser,但我需要在xml文档中使用所有数据。swift中的Xml +模式

Here我阅读,的NSXMLParser支持的模式,我在的iOS开发新的,你能告诉我一个小例子,我怎么能解析XML文档与模式,像JSON文件的NSDictionary

var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(self.data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary 

谢谢!

回答

1

我在斯威夫特使这个新的简单和轻量级的XML解析器为iOS - AEXML

你可以用它来读取这样的XML数据:

let someValue = xmlDocument["element"]["child"]["anotherChild"].value 

,或者你可以用它来构建XML字符串像这样:

let document = AEXMLDocument() 
let element = document.addChild("element") 
element.addChild("child") 
document.xmlString // returns XML string of the entire document structure 

我希望有帮助。