在XML
結構,我有:如何在Objective-C中使用NSXMLParser獲取標籤參數?
<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];
}
和它的作品beautifly的<mytag>something</mytag>
。如何獲取標籤屬性?
謝謝!完美的作品:) – Kuba 2012-04-06 13:21:53
很高興幫助你:) – 2012-04-06 13:22:55