从xml feed创建Nsmutable数组

时间:2010-06-29 13:30:51

标签: iphone objective-c cocoa-touch

我想将BlogEntries中的项目复制到我的自定义Nsmutable Array中。代码是

-(void) grabRSSFeed:(NSString *)blogAddress {

// Initialize the blogEntries MutableArray that we declared in the header
blogEntries = [[NSMutableArray alloc] init];    

// Convert the supplied URL string into a usable URL object
NSURL *url = [NSURL URLWithString: blogAddress];

// Create a new rssParser object based on the TouchXML "CXMLDocument" class, this is the
// object that actually grabs and processes the RSS data
CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease];

// Create a new Array object to be used with the looping of the results from the rssParser
NSArray *resultNodes = NULL;

// Set the resultNodes Array to contain an object for every instance of an  node in our RSS feed
resultNodes = [rssParser nodesForXPath:@"//item" error:nil];

// Loop through the resultNodes to access each items actual data
for (CXMLElement *resultElement in resultNodes) {

    // Create a temporary MutableDictionary to store the items fields in, which will eventually end up in blogEntries
    NSMutableDictionary *blogItem = [[NSMutableDictionary alloc] init];

    // Create a counter variable as type "int"
    int counter;

    // Loop through the children of the current  node
    for(counter = 0; counter < [resultElement childCount]; counter++) {

        // Add each field to the blogItem Dictionary with the node name as key and node value as the value
        [blogItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];
    }       
    // Add the blogItem to the global blogEntries Array so that the view can access it.
    [blogEntries addObject:[blogItem copy]];

}  
}

现在我想在My Custom Nsmutable数组中存储一个blogEntries的副本名称列表中的时间我是怎么回事的。

1 个答案:

答案 0 :(得分:0)

我做到了

NSMutableArray *searchArray = [[NSMutableArray alloc] init];

for (NSMutableDictionary *dictionary in blogEntries)
{ 
    //NSArray *images=[dictionary objectForKey:@"image"];
    NSArray *titlearray = [dictionary objectForKey:@"title"];
    [searchArray addObject:titlearray];
}