iOS開發中常用第三方庫的使用和配置-GDataXML

來源:互聯網
上載者:User

標籤:blog   http   使用   os   檔案   io   for   art   

這篇文章旨在給自己以後需要時能及時的查到,省得每次都去baidu. 

1. xml解析庫-GDataXML 
參考文章:http://blog.csdn.net/tangren03/article/details/7868246 
GDataXML: 
(1)GDataXML.h/m檔案 
http://code.google.com/p/gdata-objectivec-client/source/browse/trunk/Source/XMLSupport/ 
(2)DGataDefines.h GDataTargetNamespace.h 檔案 
http://code.google.com/p/gdata-objectivec-client/source/browse/trunk/Source/ 

配置過程: 
(1).引入GDataXML(4個檔案) 
<arc模式下>.對GDataXML.m增加非arc注釋 -fno-objc-arc 
(2).添加系統庫 libxml2.dylib 
(3).Head Search Path中添加 /usr/include/libxml2 
(4).Other linker flags中添加 -lxml2 
(5).xml格式 
================================== 
<?xml version="1.0" encoding="utf-8"?>  
<Users>  
    <User id="001">  
        <name>Ryan</name>  
        <age>24</age>  
    </User>  
    <User id="002">  
        <name>Tang</name>  
        <age>23</age>  
    </User>  
</Users> 
================================== 
(6).應用 
================================== 
//擷取工程目錄的xml檔案  
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"users" ofType:@"xml"];  
    NSData *xmlData = [[NSData alloc] initWithContentsOfFile:filePath];  
      
    //使用NSData對象初始化  
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData  options:0 error: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(@"-------------------");  
    } 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.