在方法头上通过
#define ELTYPE(typeName) (NSOrderedSame == [elementName caseInsensitiveCompare:@#typeName])
的写法,在方法里面的实用
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
NSString *ident = [attributeDict objectForKey:@"id"];
KMLStyle *style = [_placemark style] ? [_placemark style] : _style;
// Style and sub-elements
if (ELTYPE(Style)) {
if (_placemark) {
[_placemark beginStyleWithIdentifier:ident];
} else if (ident != nil) {
_style = [[KMLStyle alloc] initWithIdentifier:ident];
}
} else if (ELTYPE(PolyStyle)) {
[style beginPolyStyle];
} else if (ELTYPE(LineStyle)) {
[style beginLineStyle];
} else if (ELTYPE(color)) {
[style beginColor];
} else if (ELTYPE(width)) {
[style beginWidth];
} else if (ELTYPE(fill)) {
[style beginFill];
} else if (ELTYPE(outline)) {
[style beginOutline];
}
// Placemark and sub-elements
else if (ELTYPE(Placemark)) {
_placemark = [[KMLPlacemark alloc] initWithIdentifier:ident];
} else if (ELTYPE(Name)) {
[_placemark beginName];
} else if (ELTYPE(Description)) {
[_placemark beginDescription];
} else if (ELTYPE(styleUrl)) {
[_placemark beginStyleUrl];
} else if (ELTYPE(Polygon) || ELTYPE(Point) || ELTYPE(LineString)) {
[_placemark beginGeometryOfType:elementName withIdentifier:ident];
}
// Geometry sub-elements
else if (ELTYPE(coordinates)) {
[_placemark.geometry beginCoordinates];
}
// Polygon sub-elements
else if (ELTYPE(outerBoundaryIs)) {
[_placemark.polygon beginOuterBoundary];
} else if (ELTYPE(innerBoundaryIs)) {
[_placemark.polygon beginInnerBoundary];
} else if (ELTYPE(LinearRing)) {
[_placemark.polygon beginLinearRing];
}
}