开发者

How do I parse this SOAP response in my iPhone application?

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>

<Re开发者_如何学Gostaurant_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.


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/


Use an XML parser like NSXMLParser

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜