搜索XML提要usind iPhone

问题描述:

喜谁能给我如何开始编码的应用程序来搜索互联网,找到RSS XML网址的使用由用户提供的字符串提示。搜索XML提要usind iPhone

感谢前沿。

您需要使用XML解析来实现this.I建议使用touchXML

- (无效){callwebservice

NSString *path = @"YOUR URL"; 
[self grabRSSFeed:path]; 

}

编译马克 -

编译标记触摸XML

编译马克 -

- (空)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:@"//Node you want to parse" 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]]; 
        NSLog(@"Data = %@",[[resultElement childAtIndex:counter] stringValue]); 

    } 

    // Add the blogItem to the global blogEntries Array so that the view can access it. 
    [blogEntries addObject:[blogItem copy]]; 

} 
     [YourTable reloadData]; 

}

进口touchXML库在你的头文件。

感谢

+0

答复您好感谢,将为用户提供搜索字符串像CNN或BBC和应用程序需要搜索互联网来获取RSS XML的URL。你的代码是要求URL?如何用CNN或BBC这样的字符串来做到这一点。? – likki 2010-12-02 04:17:11