tags:

views:

98

answers:

2

I am getting SOAP response and when parsing the response I am getting this: (As you can see from result which is currently stored as NSString is NSLoged itself contain xml format data)

<Menus>

<Table1>

<Restaurant_Name>CHICK-FIL-A</Restaurant_Name>
<Restaurant_id>2748</Restaurant_id>
<Phone>(404) 371-1466</Phone>
<billing_city>DECATUR</billing_city>
<billing_state>GA</billing_state>
<billing_zip_code>30030</billing_zip_code>
<billing_addr1>105 EAST TRINITY PLACE</billing_addr1>

</Table1>
</Menus>

The Code for the above generated response:

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{
    if([elementName isEqualToString:@"GetMenusByZipCodeResult"])
    {       
        if(!soapResults)
        {
            soapResults = [[NSMutableString alloc] init];
        }

        recordResults = TRUE;

    }

}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{

    if(recordResults)
    {
        [soapResults appendString:string];
    }
    //NSLog(@" soap: %@", soapResults);
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
{
    if([elementName isEqualToString:@"GetMenusByZipCodeResult"])
    {

        NSLog(@"soapResult FINAL : %@",soapResults);

        recordResults = FALSE;
        result.text = soapResults;
        [soapResults release];
        soapResults = nil;
    }

}

The above mention data is result of soapResult. How to read this data? I tried to reparse it but it is not helping. Please help me.

+1  A: 

Use an XML parser like NSXMLParser

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html

unreal
Friends, I am getting this response as I am using NSXMLparser only.(I added my code to the question) Problem is the response it self contain data with tags, now how to do it? I f have to use NSXMLParser again on same data...could you please tell me how to approach for that.
Abhi
A: 

If you want a simple XML to NSDictionary converter (including the text nodes), check out http://troybrant.net/blog/2010/09/simple-xml-to-nsdictionary-converter/

Troy Brant