views:

53

answers:

1

I am parsing some XML from an RSS feed (using NSXMLParser) for a blog and would like to display the data for each post in a table cell. The XML looks like this:

<item>
    <title>Blog post 1</title>
    .
    .
</item>
<item>
    <title>Blog post 22</title>
    .
    .
</item>

How would I store this data so that it is available to my tableView:cellForRowAtIndexPath method?

I am thinking of creating a dictionary for each post item and appending these dictionaries to an NSMutableArray. This way I would be able to do something like,

cell.textLabel.text = [[mutableArray objectAtIndex: row] objectForKey: @"title"];

What do you reckon? I'm curious to know how you would approach this problem...

Thanks

A: 

This is the most common way of parsing and storing xml in objective-c utilizing nsxmlparser. Here's a snippet of my own code where I add the _locations dictionary to an array after reading the end element "locations" from the xml:

if ([elementName isEqualToString:@"location"]) {
            if ([[_location objectForKey:@"status"] isEqualToString: @"A"]) {
                [user.availableParking addObject:_location];

                [_location release];
                return;
            }
        }
ennuikiller
Thanks for this, makes sense.
ddawber