本篇文章簡單介紹如何在iOS中使用libxml
Mac OS版本:10.8.2
XCode版本:4.5.1
1. 選擇xcode工程設定<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+CjIuINGh1PE8c3Ryb25nPjxlbT50YXJnZXQ8L2VtPjwvc3Ryb25nPjwvcD4KPHA+CjMuINGh1PE8c3Ryb25nPjxlbT5TdW1tYXJ5PC9lbT48L3N0cm9uZz48L3A+CjxwPgo0LiDArbW9PHN0cm9uZz48ZW0+TGlua2VkIEZyYW1ld29ya3MgYW5kIExpYnJhcmllczwvZW0+PC9zdHJvbmc+tcS12Le9o6ywtM/CJiM0MzuwtLz8PC9wPgo8cD4KPGltZyBzcmM9"/uploadfile/Collfiles/20140430/20140430090703298.png" alt="\">
輸入libxml並選擇libxml2,按下Add按鍵
如此便可在工程中看到libxml2.dylib
如同第一張圖中,改選到Build Setting
往下拉找到Search Paths在裡面找到Header Search Paths
開啟編輯,並按下+然後輸入${SDK_ROOT}/usr/include/libxml2
如此一來便可在xcode項目中使用libxml了
#include
#include
便可include libxml
[cpp] view
plaincopy
-
void CBLibXMLUtility::saveWithLibXML(map& 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::iterator iter = data.begin(); iter != data.end(); iter++)
-
{
-
cout<<"key:"<first<<" value:"<second<
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:"<
//DebugLog("Create a xml %d bytes\n",nRel);
-
}
-
-
//release
-
-
xmlFreeDoc(doc);
-
}
這段代碼是一段簡單的范例,將map數據結構中的數據保存到xml中。