Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found another example to support different categories of the feed and I come up with the following solution:</p> <p>First declare the variable in the *.h file.</p> <pre><code>@interface XMLParser : NSObject &lt;NSXMLParserDelegate&gt;{ ... NSMutableString * currentChannel; } </code></pre> <p>In the *.m file synthesize and release the variable. In didStartElement ask which element you are currently working on. If it is a channel element, extract the title and store it in the above declared variable.</p> <pre><code>@implementation XMLParser ... @synthesize currentChannel; - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ ... if ([elementName isEqualToString:@"item"]) { ... } // title is an attribute of the element channel if ([currentElement isEqualToString:@"channel"]) { [currentChannel appendString:[attributeDict objectForKey:@"title"]]; } </code></pre> <p>}</p> <pre><code>- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ if ([elementName isEqualToString:@"item"]) { ... if ([currentChannel isEqualToString:@"Your Channel Name"]) { if ([currentCategory isEqualToString:@"Your category name"]) { [items addObject:[item copy]]; } } else { [items addObject:[item copy]]; } } } </code></pre> <p>In didEndElement ask if the item belongs to a specific channel, and if then add it only if it is the defined category. So you can add/show only rss feeds, if they belong to a certain category.</p> <p>So i've not tested it, because the channel only have one category. So I don't have to ask for the channel titel, to show only defined categories from a specific channel. But I think that should work.</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