views:

175

answers:

1

I am new to iphone development .I want parse an image url from a xml file and display it in a RSS feed.There are three image url but i want to retrieve only one url and display it.

<entry>
<id>xxxxx</id>
<title>xxx xxxx xxxx</title>
<content>xxxxxxxxxxx</content>
<media:group>
<media:thumbnail url="http://tiger.jpg"/&gt;
<media:thumbnail url="http://lion.jpg"/&gt;
<media:thumbnail url="http://elephan.jpg"/&gt;
</media:group>
</entry>

for parsing it

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{            
currentElement = [elementName copy];
if ([elementName isEqualToString:@"entry"]) {
    entry = [[NSMutableDictionary alloc] init];
    currentTitle = [[NSMutableString alloc] init];
    currentDate = [[NSMutableString alloc] init];
    NSLog(@"inside image1 ");
}else if([elementName isEqualToString:@"media:thumbnail"])
    {
        NSString* myUrl = [NSString stringWithString:[attributeDict objectForKey:@"url"]];

}   

}.

I want to retrieve only tiger image.Please help me out.Thanks.

+1  A: 

In this perticular instance you could set a class variable instead of the current local myUrl and once you get a value in it. In the code below this assumes you never initialize myURL anywhere else.

if (myURL == nil)
    myUrl = [attributeDict objectForKey:@"url"];

However this will only work the way you expect if you always want the first thumbnail URL. Unless you have some guarantee (which you haven't mentioned) that you will always want the first URL then there really isn't anything you can do to catch cases when you don't want the first URL since all of the thumbnail URLs tags and attributes are the same save for the URL.

jamone