Handling XML data with Alamofire in Swift

后端 未结 7 1975
一向
一向 2020-12-24 02:57

I started to use cocoapods with my current ios project. I need to use SOAP to get content with easy way for my ios project. I have googled it and Alamofire pod is great for

7条回答
  •  执念已碎
    2020-12-24 03:13

    If I did not misunderstand your description, I think you would like to get the XML data and parse it, right? Regarding to this, you may handle with wrong variables in the response callback. You should println(data) to check the XML document.

    For parsing XML data, you could consider SWXMLHash. The Alamofire request could look like:

    Alamofire.request(.GET, "http://my-web-service-domain.com", parameters: nil)
             .response { (request, response, data, error) in
                println(data) // if you want to check XML data in debug window.
                var xml = SWXMLHash.parse(data!)
                println(xml["UserDTO"]["FilmID"].element?.text) // output the FilmID element.
             }
    

    Further information about XML management, please check SWXMLHash.

提交回复
热议问题