Objective C - Parse SOAP xml string by using touchXML

475 views Asked by At

How to parse a soap xml by using touch XML this is soap xml string:

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

I need an array with "string" items

1

There are 1 answers

0
Rudi Angela On

More or less like this:

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