本文介绍了搜索XML供稿usind Iphone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我提示如何开始为应用程序编码以搜索互联网并使用用户提供的字符串查找rss xml网址.

hi can anyone give me hint of how to start coding for an app to search the internet and find the rss xml url's using a string provided by the user.

预先感谢.

推荐答案

您需要使用XML解析来实现此功能.建议您使用touchXML

You need to use XML parsing to implement this.I suggest use touchXML

-(void)callwebservice {

-(void)callwebservice{

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

}

-(无效)grabRSSFeed:(NSString *)blogAddress {

-(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:@"//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库.

Import touchXML library in you header file.

谢谢

这篇关于搜索XML供稿usind Iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:53