前端之家收集整理的这篇文章主要介绍了
gdata xml,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//获取工程目录的xml文件
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"users" ofType:@"xml"];
NSData *xmlData = [[NSData alloc] initWithContentsOfFile:filePath];
//使用NSData对象初始化
GdataxMLDocument *doc = [[GdataxMLDocument alloc] initWithData:xmlData options:0error:nil];
//获取根节点(Users)
GdataxMLElement *rootElement = [doc rootElement];
//获取根节点下的节点(User)
NSArray *users = [rootElement elementsForName:@"User"];
for (GdataxMLElement *user in users) {
//User节点的id属性
NSString *userId = [[user attributeForName:@"id"] stringValue];
NSLog(@"User id is:%@",userId);
//获取name节点的值
GdataxMLElement *nameElement = [[user elementsForName:@"name"] objectAtIndex:0];
NSString *name = [nameElement stringValue];
NSLog(@"User name is:%@",name);
//获取age节点的值
GdataxMLElement *ageElement = [[user elementsForName:@"age"] objectAtIndex:0];
NSString *age = [ageElement stringValue];
NSLog(@"User age is:%@",age);
NSLog(@"-------------------");
}
returnYES;
}
原文链接:https://www.f2er.com/xml/296726.html