XML parsingur SDK pour IOS

Je dois être capable d'parsingr XML pour un projet sur lequel je travaille.

Comment puis-je parsingr XML à partir d'une page Web à l'iPhone puis lire son contenu?

Suivez ceci, comment parsingr XML dans Objective c en utilisant ASIHTTPRequest et gérer toutes ces methods

-(void)parser:(NSXMLParser *)parser didStartElement:(NSSsortingng *)elementName namespaceURI:(NSSsortingng *)namespaceURI qualifiedName:(NSSsortingng *)qualifiedName atsortingbutes:(NSDictionary *)atsortingbuteDict -(void)parser:(NSXMLParser *)parser didEndElement:(NSSsortingng *)elementName namespaceURI:(NSSsortingng *)namespaceURI qualifiedName:(NSSsortingng *)qName -(void)parser:(NSXMLParser *)parser foundCharacters:(NSSsortingng *)ssortingng 

Voir ce lien aussi

  NSSsortingng *url=@"http://www.lancers.jp/work"; NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithSsortingng:url]]; NSDictionary *dict=[XMLParser dictionaryForXMLData:data error:nil]; NSLog(@"%@",[dict description]); and use below file:::::: XMLParser.h // // XMLReader.h // // Created by Troy on 9/18/10. // Copyright 2010 Troy Brant. All rights reserved. // #import <Foundation/Foundation.h> @interface XMLParser : NSObject<NSXMLParserDelegate> { NSMutableArray *dictionaryStack; NSMutableSsortingng *textInProgress; NSError **errorPointer; } + (NSDictionary *)dictionaryForXMLData:(NSData *)data error:(NSError **)errorPointer; + (NSDictionary *)dictionaryForXMLSsortingng:(NSSsortingng *)ssortingng error:(NSError **)errorPointer; @end XMLParser.m // // XMLReader.m // // Created by Troy on 9/18/10. // Copyright 2010 Troy Brant. All rights reserved. // #import "XMLParser.h" NSSsortingng *const kXMLReaderTextNodeKey = @"text"; @interface XMLParser (Internal) - (id)initWithError:(NSError **)error; - (NSDictionary *)objectWithData:(NSData *)data; @end //NSSsortingng *url=[NSSsortingng ssortingngWithFormat:@"%@",NSLocalizedSsortingng(@"locationname", nil)]; //url=[NSSsortingng ssortingngWithFormat:url,app.latnear,app.lngnear]; //NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithSsortingng:url]]; //NSDictionary *dict=[XMLReader dictionaryForXMLData:data error:nil]; @implementation XMLParser #pragma mark - #pragma mark Public methods + (NSDictionary *)dictionaryForXMLData:(NSData *)data error:(NSError **)error { XMLParser *reader = [[XMLParser alloc] initWithError:error]; NSDictionary *rootDictionary = [reader objectWithData:data]; [reader release]; return rootDictionary; } + (NSDictionary *)dictionaryForXMLSsortingng:(NSSsortingng *)ssortingng error:(NSError **)error { NSData *data = [ssortingng dataUsingEncoding:NSUTF8SsortingngEncoding]; return [XMLParser dictionaryForXMLData:data error:error]; } #pragma mark - #pragma mark Parsing - (id)initWithError:(NSError **)error { if (self = [super init]) { errorPointer = error; } return self; } - (void)dealloc { [dictionaryStack release]; [textInProgress release]; [super dealloc]; } - (NSDictionary *)objectWithData:(NSData *)data { // Clear out any old data [dictionaryStack release]; [textInProgress release]; dictionaryStack = [[NSMutableArray alloc] init]; textInProgress = [[NSMutableSsortingng alloc] init]; // Initialize the stack with a fresh dictionary [dictionaryStack addObject:[NSMutableDictionary dictionary]]; // Parse the XML NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data]; parser.delegate = self; BOOL success = [parser parse]; // Return the stack's root dictionary on success if (success) { NSDictionary *resultDict = [dictionaryStack objectAtIndex:0]; return resultDict; } return nil; } #pragma mark - #pragma mark NSXMLParserDelegate methods - (void)parser:(NSXMLParser *)parser didStartElement:(NSSsortingng *)elementName namespaceURI:(NSSsortingng *)namespaceURI qualifiedName:(NSSsortingng *)qName atsortingbutes:(NSDictionary *)atsortingbuteDict { // Get the dictionary for the current level in the stack NSMutableDictionary *parentDict = [dictionaryStack lastObject]; // Create the child dictionary for the new element, and initilaize it with the atsortingbutes NSMutableDictionary *childDict = [NSMutableDictionary dictionary]; [childDict addEnsortingesFromDictionary:atsortingbuteDict]; // If there's already an item for this key, it means we need to create an array id existingValue = [parentDict objectForKey:elementName]; if (existingValue) { NSMutableArray *array = nil; if ([existingValue isKindOfClass:[NSMutableArray class]]) { // The array exists, so use it array = (NSMutableArray *) existingValue; } else { // Create an array if it doesn't exist array = [NSMutableArray array]; [array addObject:existingValue]; // Replace the child dictionary with an array of children dictionaries [parentDict setObject:array forKey:elementName]; } // Add the new child dictionary to the array [array addObject:childDict]; } else { // No existing value, so update the dictionary [parentDict setObject:childDict forKey:elementName]; } // Update the stack [dictionaryStack addObject:childDict]; } - (void)parser:(NSXMLParser *)parser didEndElement:(NSSsortingng *)elementName namespaceURI:(NSSsortingng *)namespaceURI qualifiedName:(NSSsortingng *)qName { // Update the parent dict with text info NSMutableDictionary *dictInProgress = [dictionaryStack lastObject]; // Set the text property if ([textInProgress length] > 0) { [dictInProgress setObject:textInProgress forKey:kXMLReaderTextNodeKey]; // Reset the text [textInProgress release]; textInProgress = [[NSMutableSsortingng alloc] init]; } // Pop the current dict [dictionaryStack removeLastObject]; } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSSsortingng *)ssortingng { // Build the text value [textInProgress appendSsortingng:ssortingng]; } - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError { // Set the error pointer to the parser's error object *errorPointer = parseError; } @end