If I understand your code correctly, item
holds the currently parsed item,
and the array stories
holds all items.
So you have to allocate the stories
array first:
stories = [[NSMutableArray alloc] init];
Then you do the parsing (but you should add an error check):
NSData *xmlData=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:@"URL"]];
xmlParserObject =[[NSXMLParser alloc]initWithData:xmlData];
[xmlParserObject setDelegate:self];
if (![xmlParserObject parse]) {
// Parsing failed, report error...
}
And finally print the contents of the array:
for (NSDictionary *story in stories) {
NSLog(@"%@", [story objectForKey:@"title"]);
}
The didEndElement
method probably should look like this:
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"item"]){
[item setObject:currentTitle forKey:@"title"];
[stories addObject:item]; // <-- MOVED INTO THE IF-BLOCK
}
}