我是iphone开发的新手。我想要解析一个管状XML页面并检索其内容并显示在RSS源中。
我的xml页面是
<entry>
<id>xxxxx</id>
<title>xxx xxxx xxxx</title>
<content>xxxxxxxxxxx</content>
<media:group>
<media:thumbnail url="http://tiger.jpg"/>
</media:group>
</entry>
要检索我正在使用xml解析的内容。
- (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];
}
}
我能够检索id,title和content值并将其显示在table-view中。如何检索老虎图像URL并将其显示在table-view中。请帮助我。谢谢。
答案 0 :(得分:2)
- (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"];
}
由于此方法中已有if语句,因此使用else if this this