1.XML解析,一下代码只是将已加入xcode的XML文件进行数据解析:解析的结果是一个字典,可以通过查找字典找到文件中内容,也可将字典中信息显示到TableView的cell上面去.
- (void)viewDidLoad
{
[super viewDidLoad];
_city = [[NSMutableDictionary alloc] initWithCapacity:10];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"City" ofType:@"xml"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
GDataXMLDocument *document = [[GDataXMLDocument alloc] initWithData:data options:0 error:nil];
GDataXMLElement *root = document.rootElement;
NSArray *heArr = [NSMutableArray arrayWithArray:[root nodesForXPath:@"//henan/city" error:nil]];
NSArray *shanArr = [NSMutableArray arrayWithArray:[root nodesForXPath:@"//shandong/city" error:nil]];
[_city setObject:shanArr forKey:@"山东"];
[_city setObject:heArr forKey:@"河南"];
// Do any additional setup after loading the view, typically f