所以,我收到了一個服務的肥皂響應,現在我需要解析它。我陷入困境。對於這個迴應,我想抓住「Gzk0P」的價值。看到我的解析方法在xml下面。謝謝!NSXMLParser解析SOAP響應
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://mysvc.myservice.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:createSubmissionResponse>
<return xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">error</key>
<value xsi:type="xsd:string">OK</value>
</item>
<item>
<key xsi:type="xsd:string">link</key>
<value xsi:type="xsd:string">Gzk0P</value>
</item>
</return>
</ns1:createSubmissionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"key"]) {
NSString *title = [attributeDict valueForKey:@"value"];
NSString *test = @"";
}
}
我用這種方法。我可能沒有以最乾淨的方式做到這一點,但我基本上更新currentElementValue等於'字符串',當'字符串'等於'鏈接',然後我知道我感興趣的值接下來,所以如果currentElementValue ==「鏈接「,然後我再次更新currentElementValue等於我想要的5個字符值..無論如何。謝謝! –