我有一个 XML 文件:
<trkseg>
<trkpt lat="11.004661" lon="76.97364"></trkpt>
<trkpt lat="11.005497" lon="76.97496"></trkpt>
</trkseg>
这是我的代码:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"trkseg"])
{
self.tag = [[MRTRouteMapTag alloc]init];
NSLog(@"SRC: %@",[attributeDict objectForKey:@"lat"]);
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
[self.workingPropertyString appendString:string];
}
//event_logo, event_name, event_venue, event_date_time, race_details, event_descriptions;
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
if (self.tag)
{
NSString *trimmedString = [self.workingPropertyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// clear the string for next time
[self.workingPropertyString setString:@""];
if ([elementName isEqualToString:@"trkseg"])
{
[self.array addObject:self.tag];
self.tag = nil;
NSLog(@"Array Count ==>>>>>> %d", [self.array count]);
}
// Get Registered User Details
// ------ ------- ------------
else if ([elementName isEqualToString:@"trkpt"])
{
NSDictionary *attributeDict;
NSString *imageURLString = [attributeDict objectForKey:@"lat"];
self.tag.latitude = trimmedString;
NSLog(@"race_id ==>> %@", imageURLString);
}
}
}
这里我需要从trkpt TAG 的lat和lon值中解析数据。任何人都可以指导我实现这一目标.. 提前致谢。