2014-10-10 37 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 

我希望有幫助。