在捆绑包中,我连接到一个蓝色而不是通常的黄色的外部文件夹。在这个文件夹中有一个 xml 文件,我必须从中读取内容。
这是我从中导出“id”值的 xml 文件:
<?xml version='1.0' encoding='UTF-8'?>
<root>
<event id="2"></event>
</root>
这是我的代码:
- (void)viewDidLoad
{
NSString *pathFile = [[NSBundle mainBundle] bundlePath];
NSString *path = [[NSString alloc] initWithString:[pathFile stringByAppendingPathComponent:@"config.xml"]];
NSURL *xmlURL = [NSURL fileURLWithPath:path];
NSXMLParser *parser = [[ NSXMLParser alloc] initWithContentsOfURL:xmlURL];
NSLog(@"the parser xml is %@", parser);
//the parser xml is <NSXMLParser: 0x967d870>
[parser setDelegate:self];
BOOL success = [parser parse];
if(success == YES){
NSLog(@"success");
} else {
NSLog(@" not success"); //is not success, why?
}
[parser release];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
//in this method does not enter
if ([elementName isEqualToString:@"event"]){
NSLog(@" %@", elementName);
}
}