本文主要是介绍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;
}
这篇关于gdata xml的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!