在Swift中将XML字符串解析为对象

时间:2016-09-24 08:59:24

标签: ios swift serialization deserialization

我使用SOAP Web服务获取XML,例如:

具有某些属性并带有对象的XML:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:contactFile" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:SendLeadResponse><SendLeadReturn xsi:type="ns1:SendLeadResponse"><code xsi:type="xsd:integer">1</code><message xsi:type="xsd:string">0</message><option xsi:type="xsd:option"><num xsi:type="xsd:int">999</num><tag xsi:type="xsd:boolean">false</tag><refused xsi:nil="true"/></option></SendLeadReturn></ns1:SendLeadResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

我的对象

class SendLeadReponse: Reponse {
    var option: Option


    init(code: Int, message: String, option: Option){
        self.option = option
        super.init(code: code, message: message)
    }


}


class Option {
    var num: Int
    var tag: Bool
    var refused: CGVector


    init(num: Int, tag: Bool, refused: CGVector){
        self.num = num
        self.tag = tag
        self.refused = refused
    }


}

如何将XML放入对象中?

0 个答案:

没有答案