Hi! I have followed this tutorial and the parsing part is working allright. My problem is that when printing out the values that I store into the object (in my case the object is a car) always remains null. I save all the objects into an MutableArray which always seems to have a length/count == 0...what am I doing wrong? The array is, as can be seen in the code, defined in the delegate class...
- (XMLParser *) initXMLParser {
[super init];
appDelegate = (Car2GoAppDelegate *) [[UIApplication sharedApplication]delegate];
currentElementValue = [[NSMutableString alloc]init];
return self;
}
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attribute:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"kml"]) {
appDelegate.cars = [[NSMutableArray alloc]init];
}
else if([elementName isEqualToString:@"Placemark"]) {
aCar = [[Car alloc]init];
}
else
return;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *) string {
[currentElementValue appendString:string];
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *) elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"kml"])
return;
if([elementName isEqualToString:@"Style"])
return;
if([elementName isEqualToString:@"IconStyle"])
return;
if([elementName isEqualToString:@"Icon"])
return;
if([elementName isEqualToString:@"color"])
return;
if([elementName isEqualToString:@"colorMode"])
return;
if([elementName isEqualToString:@"scale"])
return;
if([elementName isEqualToString:@"href"])
return;
if([elementName isEqualToString:@"styleUrl"])
return;
if([elementName isEqualToString:@"a"])
return;
if([elementName isEqualToString:@"Placemark"]) {
[appDelegate.cars addObject:aCar];
[aCar release];
aCar = nil;
}
else if([elementName isEqualToString:@"name"]) {
[aCar setValue:currentElementValue forKey:elementName];
}
else if([elementName isEqualToString:@"description"]) {
[aCar setValue:currentElementValue forKey:elementName];
[currentElementValue setString:@""];
}
else if([elementName isEqualToString:@"coordinates"]) {
[aCar setValue:currentElementValue forKey:elementName];
[currentElementValue setString:@""];
NSLog(@"aCar coordinates:%@", [aCar coordinates]);
}
else
return;
}
- (void) dealloc {
[aCar release];
[currentElementValue release];
[super dealloc];
}
@end
/loop