在Swift中解析XML Web服务响应

时间:2015-08-19 08:24:19

标签: ios swift web-services soap xml-parsing

我需要解析来自Web Service的响应XML消息。 消息如下:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><HelloAppleResponse xmlns="http://testest.org/"><HelloAppleResult>StringThatINeed</HelloAppleResult></HelloAppleResponse></soap:Body></soap:Envelope>

消息在变量调用strData:

var strData = NSString(data: data, encoding: NSUTF8StringEncoding)

我需要使用NSXMLParser,但我不知道如何使用它。

    // NSXMLParserDelegate

  func parser(parser: NSXMLParser!, didStartElement elementName: String!, namespaceURI: String!, qualifiedName qName: String!, attributes attributeDict: NSDictionary!) {
        currentElementName = elementName
    }


func parser(parser: NSXMLParser, foundCharacters string: String?) {
    if currentElementName == "HelloAppleResult" {
        txtResult.text = string
    }
}

0 个答案:

没有答案
相关问题