I want to parse a XML from URL which is RSS of my blog with SWXMLHASH or AEXML libraries. I found a solution for this but when I tried the solution my app crashed. It is the encountered problem: fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
And there are my codes which are in viewDidLoad:
` Alamofire.request("http://myblog.com/feed").responseJSON { response in
if let data = response.data {
let xml = SWXMLHash.parse(data)
let news = xml["rss"]["channel"]["item"][0]["title"].element?.text
print(news!)
}
}
`
Is there any other solution for this? I don't want to use NSXMLParser, I want to use these kind of libraries or If it is exist any up-to-date library, I can use.
Thank you for your help!
Use
Alamofire.request("http://myblog.com/feed").response
not Alamofire.request("http://myblog.com/feed").responseJSON
I used AEXML.. try this
Alamofire.request("http://myblog.com/feed").response { res in
guard let xml = res.data else {
return
}
var options = AEXMLOptions()
options.parserSettings.shouldProcessNamespaces = false
options.parserSettings.shouldReportNamespacePrefixes = false
options.parserSettings.shouldResolveExternalEntities = false
do {
let xmlDoc = try AEXMLDocument(xml: xml, options: options)
print(xmlDoc.root["channel"]["item"]["title"].value!)
} catch let error {
print(error)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.