GDataXMLnode
1.下载连接:http://code.google.com/p/gdata-objectivec-client/downloads/list下载“gdata-objective-c client library.”web
2.项目引入: 解压缩文件,找到Source\XMLSupport,而且将其中的GDataXMLNode.h 和 GDataXMLNode.m文件拖到项目中objective-c
3. 项目编译支持配置:ui
1). 选中项目,选中“Build Settings”标签页google
2 ). 将Build Settings页中,顶部的“Basic”标签切换到“All”spa
3). 找到“Paths\Header Search Paths”项,并添加“/usr/include/libxml2”到列表中code
4). 找到“Linking\Other Linker Flags”项,并添加“-lxml2”到列表中orm
4。 在要用到的地方引入“#import "GDataXMLNode.h"”xml
而后就可使用了,下面的是一个本身项目 中使用的小例子ci
/** 解析webservice返回的XML成一个NSDictionary 参数:content ,要解析的数据 参数:path ,要解析的XML数据一个根节点 返回:NSDictionary */ + (NSDictionary *)getWebServiceXMLResult:(NSString *) content xpath:(NSString *)path { NSMutableDictionary *resultDict = [[NSMutableDictionary alloc] init]; content = [content stringByReplacingOccurrencesOfString:@"<" withString:@"<"]; content = [content stringByReplacingOccurrencesOfString:@">" withString:@">"]; content = [content stringByReplacingOccurrencesOfString:@"xmlns" withString:@"noNSxml"]; NSError *docError = nil; GDataXMLDocument *document = [[GDataXMLDocument alloc] initWithXMLString:content options:0 error:&docError]; if(!docError) { NSArray *children = nil; children = [document nodesForXPath:[NSString stringWithFormat:@"//%@",path] error:&docError]; if(!docError) { if(children && [children count]>0) { GDataXMLElement *rootElement = (GDataXMLElement *)[children objectAtIndex:0]; NSArray *nodearr = [rootElement children]; for (int i = 0; i<[nodearr count]; i++) { GDataXMLElement *element = (GDataXMLElement *)[nodearr objectAtIndex:i]; [resultDict setObject:[element stringValue] forKey:[element name]]; } } } } [document release]; return [resultDict autorelease]; }