在Iphone中搜索XML提要

在Iphone中搜索XML提要,iphone,search,rss,Iphone,Search,Rss,大家好,有谁能给我一些提示,告诉我如何开始为应用程序编码,以便使用用户提供的字符串搜索互联网并找到rss xml url 首先谢谢。您需要使用XML解析来实现这一点。我建议使用touchXML -(void)callwebservice{ NSString *path = @"YOUR URL"; [self grabRSSFeed:path]; } 布拉格标记- pragma标记触摸XML 布拉格标记- -(void)grabsfeed:(NSString*)博客地址{

大家好,有谁能给我一些提示,告诉我如何开始为应用程序编码,以便使用用户提供的字符串搜索互联网并找到rss xml url


首先谢谢。

您需要使用XML解析来实现这一点。我建议使用touchXML

-(void)callwebservice{

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

布拉格标记- pragma标记触摸XML 布拉格标记- -(void)grabsfeed:(NSString*)博客地址{

// 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];
//初始化我们在标头中声明的blogEntries MutableArray
blogEntries=[[NSMutableArray alloc]init];
//将提供的URL字符串转换为可用的URL对象
NSURL*url=[NSURL URLWithString:blogAddress];
//基于TouchXML“CXMLDocument”类创建一个新的rssParser对象,这是
//对象,该对象实际捕获和处理RSS数据
CXMLDocument*rssParser=[[CXMLDocument alloc]initWithContentsOfURL:url选项:0错误:nil]autorelease];
//创建一个新的数组对象,用于rssParser结果的循环
NSArray*resultNodes=NULL;
//将resultNodes数组设置为包含RSS提要中每个节点实例的对象
resultNodes=[rssParser nodesForXPath:@”//要分析的节点“error:nil];
//循环遍历resultNodes以访问每个项目的实际数据
对于(resultNodes中的CXMLElement*resultElement){
//创建一个临时的MutableDictionary来存储其中的items字段,它最终将在blogEntries中结束
NSMutableDictionary*blogItem=[[NSMutableDictionary alloc]init];
//创建类型为“int”的计数器变量
整数计数器;
//循环遍历当前节点的子节点
用于(计数器=0;计数器<[resultElement childCount];计数器++){
//将每个字段添加到blogItem字典中,节点名称作为键,节点值作为值
[blogItem setObject:[[resultElement childAtIndex:counter]stringValue]forKey:[[resultElement childAtIndex:counter]名称]];
NSLog(@“Data=%@,[[resultElement childAtIndex:counter]stringValue]);
}
//将blogItem添加到全局blogEntries数组中,以便视图可以访问它。
[blogEntries addObject:[blogItem copy]];
}
[您的表重新加载数据];
}

在头文件中导入touchXML库


感谢

hi感谢回复,用户将提供CNN或BBC等搜索字符串,应用程序需要搜索互联网才能获得rss xml URL。您的代码要求URL?如何用像CNN或BBC这样的字符串来完成它。?