1. 从http://code.google.com/p/gdata-objectivec-client/downloads/list下载“gdata-objective-c client library.”

2. 解压缩文件,找到Source\XMLSupport,并且将其中的GDataXMLNode.h 和 GDataXMLNode.m文件拖到项目中

3. 选中项目,选中“Build Settings”标签页

4. 将Build Settings页中,顶部的“Basic”标签切换到“All”

5. 找到“Paths\Header Search Paths”项,并添加“/usr/include/libxml2”到列表中

6. 找到“Linking\Other Linker Flags”项,并添加“-lxml2”到列表中

如何在项目中设置使用GDataXML解析类库

 在需要调用GDataXML的代码文件头部,加入:
#import "GDataXMLNode.h"
应用示例:创建DOM结构

NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:@"test.xml"];
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&error];

基于XPath解析

 NSArray *themeAttr = [doc nodesForXPath:@"//theme" error:&error];
for(GDataXMLElement *themeElement in themeAttr){
GDataXMLNode *themeIDNode = [themeElement attributeForName:@"id"];//解析属性
int themeID = [themeIDNode.stringValue intValue];//数字
//theme url
GDataXMLNode *themeURLNode = [themeElement attributeForName:@"url"];//字符串
NSString *themeURL = themeURLNode.stringValue;
}

 

相关文章:

  • 2021-04-12
  • 2021-07-26
  • 2021-05-26
  • 2021-05-12
  • 2021-06-23
  • 2021-04-12
  • 2022-02-07
  • 2021-10-16
猜你喜欢
  • 2021-06-08
  • 2022-12-23
  • 2022-01-03
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案