2010-11-30 24 views
0

Salut quelqu'un peut-il me donner un indice de la façon de commencer à coder pour une application pour rechercher sur Internet et trouver l'url rss xml en utilisant une chaîne fournie par l'utilisateur.Recherche de flux XML usind Iphone

merci d'avance.

Répondre

1

Vous devez utiliser parsing XML pour mettre en œuvre this.I suggèrent l'utilisation touchXML

- (void) callwebservice {

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

}

marque pragma - marque

pragma tactile XML

marque de pragma -

- (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]; 

}

bibliothèque d'importation touchXML dans votre fichier d'en-tête.

Merci

+0

Salut, merci pour la réponse, les utilisateurs fourniront des chaînes de recherche comme CNN ou BBC et l'application doit rechercher Internet pour obtenir rss urls xml. votre code demande une URL? comment le faire avec juste une chaîne comme CNN ou BBC.? – likki