如何在RSS Feed中找到图像链接

时间:2014-01-06 08:46:13

标签: ios rss

我正在创建基于RSS Feed的应用。我正在尝试解析图像链接。但我没有得到链接。代码如下 -

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

    // Autorelease pool for secondary threads
    //    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    // Initialize the blogEntries MutableArray that we declared in the header
    feedEntries = [[NSMutableArray alloc] init];
    // Convert the supplied URL string into a usable URL object
    NSURL *url = [NSURL URLWithString:blogAddress];
    if(url==nil)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"RSS Feed" message:@"Please enter a valid RSS feed URL."
                                                       delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [alert show];

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

        if(rssParser==nil)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"RSS Feed" message:@"Please enter a valid RSS feed URL."
                                                           delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [alert show];

        }
        else
        {
            // 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 *feedItem = [[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
                    if([[resultElement childAtIndex:counter] stringValue]!=nil)
                        [feedItem 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.
                [feedEntries addObject:feedItem];
            }

            NSLog(@"Feeds = %@",feedEntries);

            [feedEntries writeToFile:[[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"Feeds.plist"] atomically:YES];

            //            [self performSelectorOnMainThread:@selector(reloadTableData:) withObject:nil waitUntilDone:NO];

        }

    }

}

如何获取有关特定新闻的图像链接?

0 个答案:

没有答案