【问题标题】:Objective C - Parse SOAP xml string by using touchXMLObjective C - 使用 touchXML 解析 SOAP xml 字符串
【发布时间】:2014-03-31 17:39:38
【问题描述】:
如何使用 touch XML 解析一个肥皂 xml
这是肥皂 xml 字符串:
<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><seach_seriResponse xmlns=\"http://tempuri.org/\"><seach_seriResult><string>abc</string><string>def</string><string>ghi</string></seach_seriResult></seach_seriResponse></soap:Body></soap:Envelope>
我需要一个包含“字符串”项的数组
【问题讨论】:
标签:
ios
objective-c
xml
soap
touchxml
【解决方案1】:
差不多是这样的:
NSData* XMLData = ... (assuming you have your XML in an NSData)
CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];
NSMutableDictionary *mappings = [NSMutableDictionary dictionary];
[mappings setObject:@"http://schemas.xmlsoap.org/soap/envelope/" forKey:"soap"];
[mappings setObject:@"http://tempuri.org/" forKey:"tempuri"];
NSArray *nodes = [doc nodesForXPath:@"//soap:Envelope/soap:Body/tempuri:search_seriResponse/tempuri:string" namespaceMappings:mappings error:&err];