GDataXMLNode解析xml文件
来源:互联网 发布:双色球最全缩水软件 编辑:程序博客网 时间:2024/04/29 20:04
转载请标明出处
欢迎交流
zltqzj@163.com
我是一个单线程妞~
NSString* path = [[NSBundle mainBundle] pathForResource:@"StudentXML" ofType:@"xml"]; NSData* data = [[NSData alloc] initWithContentsOfFile:path]; GDataXMLDocument* doc = [[GDataXMLDocument alloc] initWithData:data options:0 error:nil]; GDataXMLElement* root = [doc rootElement];//所有内容 // 取标签中的内容方法:1,路径。2,childAtIndex //(1)路径 NSArray* fistName = [root nodesForXPath:@"//student/name/fistName" error:nil];// 所t有标签为fistName的元素。 NSLog(@"1:%@",[[fistName objectAtIndex:1] stringValue]); // (2)childAtIndex GDataXMLNode* lastName = [[[root childAtIndex:1] childAtIndex:0] childAtIndex:1]; NSLog(@"2:%@",[lastName stringValue]);
代码下载地址:http://download.csdn.net/detail/sijiazhentan/6270435
解析稍微复杂的页面:http://api.hudong.com/iphonexml.do?type=focus-c
代码如下:
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController@synthesize recieveData = _recieveData;- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; NSURL* url = [NSURL URLWithString:@"http://api.hudong.com/iphonexml.do?type=focus-c"]; NSURLRequest* request = [NSURLRequest requestWithURL:url]; [NSURLConnection connectionWithRequest:request delegate:self]; // Do any additional setup after loading the view from its nib.}- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ _recieveData = [[NSMutableData alloc] init]; }- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ [self.recieveData appendData:data];}- (void)connectionDidFinishLoading:(NSURLConnection *)connection{ NSString* str = [[NSString alloc] initWithData:self.recieveData encoding:NSUTF8StringEncoding]; _recieveData = nil; GDataXMLDocument* doc = [[GDataXMLDocument alloc] initWithXMLString:str options:0 error:nil]; GDataXMLElement* root = [doc rootElement]; NSArray* array =[root nodesForXPath:@"//response/docList/docInfo" error:nil]; for (int i =0; i<array.count; i++) { NSLog(@"每项内容的题目:%@",[[[[array objectAtIndex:i] elementsForName:@"docTitle"] objectAtIndex:0] stringValue] ); } _recieveData = nil; }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
- GDataXMLNode解析xml文件
- GDataXMLNode解析xml文件的使用
- GDataXMLNode库 XML解析
- GDataXMLNode:xml解析库
- 采用GDataXMLNode进行xml解析
- 数据解析(二)解析XML之GDataXMLNode
- DOM解析(GDataXMLNode)详解,xml解析
- IOS开发中使用GDataXmlNode解析xml
- iOS 用GDataXMLNode创建和解析XML
- iOS 用GDataXMLNode创建和解析XML
- iOS的XML解析库:GDataXMLNode
- iOS-XML解析之-GDataXMLNode
- iOS之GDataXMLNode对XML解析
- GDataXMLNode解析xml数据的简单应用
- iOS GDataXMLNode 解析XML DOM方式 总结
- XML数据解析(GDataXMLNode的使用)
- XML解析之dom方式GDataXMLNode
- GDataXMLNode 解析
- C#中Dictionary的用法及用途实例
- uva 11300 Spreading the Wealth
- 黑马程序员--GUI
- 数据库连接及操作
- ubuntu下环境变量配置
- GDataXMLNode解析xml文件
- 世间事,除了生死,哪一件不是闲事
- 数据类型转换
- UVa 10916 Factstone Benchmark (数学&阶乘的处理技巧)
- 优化Tomcat篇:调增tomcat6响应池
- 回溯法求装载问题
- 关于做笔记
- 解决校园网中无法创建socket问题
- javascript实现树形目录的收缩与展开