Hi,
how can I extract the titel of a RSS channel while not getting in conflict with the title element of a news item?
If an element was found:
- (void)parser:(NSXMLParser *) parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
...
if ([elementName isEqualToString:@"channel") {
[currentChannel release];
currentChannel = nil;
currentChannel = [[NSMutableString alloc] init];
}
if ([elementName isEqualToString:@"item"]) {
...
}
}
If the end-tag was found:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"channel") {
[channel setObject:currentChannelTitle forKey:@"title"];
}
if ([elementName isEqualToString:@"item"]) {
...
}
Do the parsing stuff:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([currentElement isEqualToString:@"title") {
[currentChannelTitle appendString:string forKey:@"title"];
}
if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
}
...
}
And in the last part I have the problem. I have two "title" attributes. One for the "channel" element and one for the child element of it ("item"). But I need a distinction somehow. But how?