I have an XML file that looks like this:
Ireland
You need to use XML parser, Use NSXMLParser to parse you data. Below is the apple sample code of ImageMap in which they have used the NSXMLParser to parse XML content.
http://developer.apple.com/library/mac/#samplecode/ImageMap/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009015
This may help
Accessing specific child elements when parsing RSS with NSXMLParser
Use NSXMLParser
implement the delegate for this class ... <NSXMLParserDelegate>
implement the methods for this parser...
YOU will need the following methods..
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
You can read this tutorial; it is simple to use.
Try this . . .
int element=0; [self parseXMLFileAtURL:filepath];
following methods are the delegates of NSXMLParser
- (void)parseXMLFileAtURL:(NSString *)URL { NSURL *xmlURL = [NSURL fileURLWithPath:URL]; parser = [[ NSClassFromString(@"NSXMLParser") alloc] initWithContentsOfURL:xmlURL]; [parser setDelegate:self]; [parser setShouldProcessNamespaces:NO]; [parser setShouldReportNamespacePrefixes:NO]; [parser setShouldResolveExternalEntities:NO]; [parser parse]; } - (void)parserDidStartDocument:(NSXMLParser *)parser { NSLog(@"found file and started parsing"); } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if(([elementName compare:@"SourceCountry"])==NSOrderedSame) element=1; if(([elementName compare:@"SourcePort"])==NSOrderedSame) element=2; if(([elementName compare:@"DestinationCountry"])==NSOrderedSame) element=3; if(([elementName compare:@"DestinationPort"])==NSOrderedSame) element=4; } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if (element==1) { [TotalXMLArray addObject:string]; element=0; } if (element==2) { [TotalXMLArray addObject:string]; element=0; } if (element==3) { [TotalXMLArray addObject:string]; element=0; } if (element==4) { [TotalXMLArray addObject:string]; element=0; } }