开发者

Parse XML Using NSXMLParser for display in table view

I am parsing some XML from an RSS feed (using NSXMLParser) for a blog and would like to display the data for e开发者_StackOverflowach 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


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;
            }
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜