I'm really new to this and I'm trying to read an RSS feed, and so far everything is good. This is how I do it:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"item"]) {
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
[item setObject:currentImage forKey:@"enclosure"];
[stories addObject:[item copy]];
NSLog(@"adding story: %@", currentTitle);
}
}
The problem is the enclosure. Which looks like this in the XML:
<enclosure length="150" url="urltoimage.jpg" type="image/jpeg" />
How do I get url attribute from that element from within my function?
EDIT The XML looks like this:
<item>
<title>...</title>
<link>...</link>
<description>...</description>
<pubDate>...</pubDate>
<enclosure length="150" url="urltoimage.jpg" type="image/jpeg" />
</item>
And my foundCharacters function looks like this:
- (void)parser: (NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
[currentLink appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
[currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
[currentDate appendString:string];
}
}