Reputation: 5137
so, I have received a soap response from a service and now I need to parse it. I am getting stuck. For this response, I want to grab the "Gzk0P" value toward the bottom. See my parse method below the xml. thanks!
<?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 = @"";
}
}
Upvotes: 0
Views: 1219
Reputation: 12787
You are doing wrong you cant access the values form attributed dict. attributed dict is used when values written in the same tag as attribute see this
lt key gt xsi:type="xsd:string" value="Gzk0P">link lt /key gt
But here is condition is different, value is an separate tag in tag thats why you need to reach inside the value tag and in foundCharacters
method you can access that value.
code some thing like this
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
currentElementValue=string;
NSLog(@"Processing Value: %@", currentElementValue);
}
Upvotes: 1
Reputation: 10393
There are two things associated with your xml.
For 1 - You can simply parse and use the last found character for the value tag as your output.
For 2 - You will have to find a way where you can identify which value you would want to parse. In this case the xml will need to be edited , either modify your tag or add a attribute.
Drop a comment in case you need more info.
Upvotes: 0
Reputation: 1003
Try this way, though I have not tested this one,but I hope this will work
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
key = nil;
[stringValue release];
stringValue = nil;
if([elementName isEqualToString:@"item"]){
if([elementName isEqualToString:@"value"]){
key = @"value";
return;
}}
Upvotes: 0