Note that there are some explanatory texts on larger screens.

plurals
  1. POExtract channel title from RSS feed using NSXMLParser
    text
    copied!<p>how can I extract the title of a RSS channel while not getting in conflict with the title element of a news item?</p> <p>If an element was found:</p> <pre><code>- (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"]) { ... } } </code></pre> <p>If the end-tag was found:</p> <pre><code>- (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"]) { ... } </code></pre> <p>Do the parsing stuff:</p> <pre><code>- (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]; } ... } </code></pre> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload