如何在項目中設置使用GDataXML解析類庫


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的代碼文件頭部,加入:
#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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM