如何在iOS中使用libxml

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   tar   

本文轉載至 http://blog.csdn.net/cloudhsu/article/details/8087628

 

1. 選擇xcode工程設定

2. 選擇target

3. 選擇Summary

4. 拉到Linked Frameworks and Libraries的地方,按下+按鍵

輸入libxml並選擇libxml2,按下Add按鍵

如此便可在工程中看到libxml2.dylib

如同第一張圖中,改選到Build Setting

往下拉找到Search Paths在裡面找到Header Search Paths

開啟編輯,並按下+然後輸入${SDK_ROOT}/usr/include/libxml2

如此一來便可在xcode項目中使用libxml了

 

#include <libxml2/libxml/parser.h>

#include <libxml2/libxml/tree.h>

便可include libxml

 

[cpp] view plaincopy
  1. void CBLibXMLUtility::saveWithLibXML(map<string,string>& data,const string& fileName)  
  2. {  
  3.     // create xml document  
  4.     xmlDocPtr doc = xmlNewDoc(BAD_CAST"1.0");  
  5.     xmlNodePtr root = xmlNewNode(NULL,BAD_CAST"CloudBoxRoot");  
  6.   
  7.     //set root  
  8.     xmlDocSetRootElement(doc,root);  
  9.   
  10.     for(map<string,string>::iterator iter = data.begin(); iter != data.end(); iter++)  
  11.     {  
  12.         cout<<"key:"<<iter->first<<"   value:"<<iter->second<<endl;  
  13.         xmlNewTextChild(root, NULL, BAD_CAST (*iter).first.c_str(), BAD_CAST (*iter).second.c_str());  
  14.     }  
  15.   
  16.     //save xml  
  17.   
  18.     int nRel = xmlSaveFile(fileName.c_str(),doc);  
  19.   
  20.     if (nRel != -1)  
  21.     {  
  22.         cout<<"create a xml:"<<nRel<<"bytes"<<endl;  
  23.         //DebugLog("Create a xml %d bytes\n",nRel);  
  24.     }  
  25.   
  26.     //release  
  27.   
  28.     xmlFreeDoc(doc);  
  29. }  


這段代碼是一段簡單的範例,將map資料結構中的資料儲存到xml中。

其他關於libxml的使用請參照我之前的文章"libxml教程"

範例代碼下載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.