Graphics Programs Reference
In-Depth Information
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
NSLog(@"%@ found a %@ element", self, elementName);
if ([elementName isEqual:@"channel"]) {
// If the parser saw a channel, create new instance, store in our ivar
channel = [[RSSChannel alloc] init];
// Give the channel object a pointer back to ourselves for later
[channel setParentParserDelegate:self];
// Set the parser's delegate to the channel object
// There will be a warning here, ignore it warning for now
[parser setDelegate:channel];
}
}
Build and run the application. You should see a log message that the channel was found. If
you don't see this message, double-check that the URL you typed in fetchEntries is
correct.
Now that the channel is sometimes the parser's delegate, it needs to implement
NSXMLParserDelegate methods to handle the XML. The RSSChannel instance
will catch the metadata it cares about along with any item elements.
The channel is interested in the title and description metadata elements, and you
will store those strings that the parser finds in the appropriate instance variables. When the
start of one of these elements is found, an NSMutableString instance will be created.
When the parser finds a string, that string will be concatenated to the mutable string.
In RSSChannel.h , declare that the class conforms to NSXMLParserDelegate and
add an instance variable for the mutable string.
@interface RSSChannel : NSObject <NSXMLParserDelegate>
{
NSMutableString *currentString;
}
In RSSChannel.m , implement one of the NSXMLParserDelegate methods to catch
the metadata.
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
NSLog(@"\t%@ found a %@ element", self, elementName);
if ([elementName isEqual:@"title"]) {
Search WWH ::




Custom Search