我需要解析来自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
}
}