Swift XML parsing library and swiftxml Parsing
After filtering in CocoaPods, it is easy to use and sort it out.
If necessary, enter:
pod search xml
This will search for a lot of third-party libraries related to Xml
SwiftyXMLParser is a third-party library for xml parsing in Swift. It supports indexing and keyValue access,
Environment and language support: iOS 8.0 + and Swift 2.0 +
Usage:
Let urlStr = ApiUrl + "/" + xmlFile (newsType) Alamofire. request (. GET, urlStr ). responseData {(response) in let xml = XML. parse (response. result. value !) Let channel = xml ["rss"] ["channel"] let items = channel ["item"] var array: [XPNews] = [] for item in items {let model: XPNews = XPNews () model. newsTitle = item ["title"]. text model. newsLink = item ["link"]. text model. newsDesc = item ["description"]. text model. newsTime = item ["pubdate"]. text ?. ToDateWith ("yyyy-MM-dd HH: mm: ss") model. newsTypeStr = item ["category"]. text model. newsThumb = item ["enclosure"]. attributes ["url"]! Array. append (model)} if (finishedHandler! = Nil) {finishedHandler! (Msg: "retrieved successfully", responseObject: array )}}
For more information, see GitHub.
GitHub address: https://github.com/yahoojapan/SwiftyXMLParser