標籤: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
- void CBLibXMLUtility::saveWithLibXML(map<string,string>& data,const string& fileName)
- {
- // create xml document
- xmlDocPtr doc = xmlNewDoc(BAD_CAST"1.0");
- xmlNodePtr root = xmlNewNode(NULL,BAD_CAST"CloudBoxRoot");
-
- //set root
- xmlDocSetRootElement(doc,root);
-
- for(map<string,string>::iterator iter = data.begin(); iter != data.end(); iter++)
- {
- cout<<"key:"<<iter->first<<" value:"<<iter->second<<endl;
- xmlNewTextChild(root, NULL, BAD_CAST (*iter).first.c_str(), BAD_CAST (*iter).second.c_str());
- }
-
- //save xml
-
- int nRel = xmlSaveFile(fileName.c_str(),doc);
-
- if (nRel != -1)
- {
- cout<<"create a xml:"<<nRel<<"bytes"<<endl;
- //DebugLog("Create a xml %d bytes\n",nRel);
- }
-
- //release
-
- xmlFreeDoc(doc);
- }
這段代碼是一段簡單的範例,將map資料結構中的資料儲存到xml中。
其他關於libxml的使用請參照我之前的文章"libxml教程"
範例代碼下載