2014-03-31 85 views
0

解析SOAP XML字符串如何使用觸摸XML 來解析SOAP XML這是SOAP XML字符串:目標C - 使用touchXML

<?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> 

我需要 「字符串」 元素的數組

回答

0

或多或少像這樣:

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];