开发者

How to parse the second child node from xml page in iphone

I am new to iphone development.I want parse an you-tube XML page and retrieve its contents and display in a RSS feed.

my xml page is

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

To retrieve the content i am using xml parsing.

- (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];
    currentcontent = [[NSMutableString alloc] init];
    }

}


- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{     
if ([elementName isEqualToString:@"entry"]) {
    [entry setObject:currentTitle forKey:@"title"];
    [entry setObject:currentDate forKey:@"content"];
    [stories addObject:[entry copy]];
    }}

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

if ([currentElement isEqualToString:@"title"]) {
    [currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"content"]) {
    [currentLink appendString:string];
 }
 }

I am able to r开发者_StackOverflow中文版etrieve id , title and content value and display it in a table-view.How can i retrieve tiger image URL and display it in table-view.Please help me out.Thanks.


   - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{            

    currentElement = [elementName copy];
    if ([elementName isEqualToString:@"media:thumbnail"])
    imageUrl=[attributeDict objectForKey:@"url"];
}

Since you already have an if statement in this method, use else if for this one

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜