This article briefly introduces how to use libxml in IOS
Mac OS Version: 10.8.2
Xcode version: 4.5.1
1. Select xcode Project Settings
2. SelectTarget
3. SelectSummary
4. PullLinked frameworks and librariesPlace, press + button
InputLibxmlAnd selectLibxml2, Press the Add button
In this way, you can see libxml2.dylib in the project.
As in the first figure, selectBuild setting
Pull down and findSearch pathsFindHeader search paths
Enable editing, press +, and enter${Sdk_root}/usr/include/libxml2
In this way, libxml can be used in the xcode project.
# Include <libxml2/libxml/parser. h>
# Include <libxml2/libxml/tree. h>
You can include libxml
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);}
This code is a simple example to save the data in the map data structure to XML.
For more information about how to use libxml, see my previous article "libxml tutorial"
Sample Code download