在XML
结构中我有:
<font fontsize="10" fontcolor="#000000" fontface="file.ttf"/>
我如何使用字体大小、颜色和面部NSXMLParser
?当然我有标准的实现
-(id)init
{
self = [super init];
parser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"myxmlfile" ofType:@"xml"]]];
[parser setDelegate:self];
[parser parse];
return self;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
NSLog(@"Started Element %@", elementName);
element = [NSMutableString string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSLog(@"Found an element named: %@ with a value of: %@", elementName, element);
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (element == nil)
element = [[NSMutableString alloc] init];
[element appendString:string];
}
它适用于<mytag>something</mytag>
. 如何获取标签属性?