下面是我写的解析器..
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"RESULTS"]) {
//Initialize the array.
//appDelegate.maps = [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:@"COLUMN"]) {
//Initialize the book.
amaps = [[MapDetails alloc] init];
dict = [[NSDictionary alloc] initWithDictionary:attributeDict];
if ([[attributeDict objectForKey:@"NAME"] isEqualToString:@"NAME"]) {
}
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
str123=[NSString stringWithFormat:@"%@",string];
}
// this delegate method is called if an error occurs in locating your current location
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"STEP 3: Failed!!! Finding location : %@ ", error);
if ( kCLErrorDenied) {
} else {
// We handle all non-CoreLocation errors here
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"RESULTS"])
return;
if([elementName isEqualToString:@"COLUMN"])
{
amaps.NAME = [NSString stringWithString:str123];
NSLog(@"%@",amaps.NAME);
if ([[dict objectForKey:@"NAME"] isEqualToString:@"NAME"]) {
[arrName addObject:[NSString stringWithFormat:@"%@",amaps.NAME]];
NSLog(@"arr %@",arrName);
}
if ([[dict objectForKey:@"NAME"] isEqualToString:@"ANAME"]) {
[arrArabName addObject:[NSString stringWithFormat:@"%@",amaps.NAME]];
NSLog(@"arr %@",arrArabName);
}
if ([[dict objectForKey:@"NAME"] isEqualToString:@"YCOORD_WGS"]) {
[arrLatitude addObject:[NSString stringWithFormat:@"%@",amaps.NAME]];
NSLog(@"arr %@",arrLatitude);
}
if ([[dict objectForKey:@"NAME"] isEqualToString:@"XCOORD_WGS"]) {
[arrLongitude addObject:[NSString stringWithFormat:@"%@",amaps.NAME]];
NSLog(@"arr %@",arrLongitude);
}
}
}