This article provides a quick overview of how to use Libxml in iOS
Mac OS version: 10.8.2
Xcode version: 4.5.1
1. Select Xcode Project Settings
2. Select target
3. Select Summary
4. Pull to Linked frameworks and Libraries , press the + button
Enter libxml and select libxml2, press the Add button
So you can see the libxml2.dylib in the project.
As in the first picture, the re-election to Build Setting
Pull down to find search Paths Find the Header search Paths
Open the Edit and press + and enter ${sdk_root}/usr/include/libxml2
This allows you to use Libxml in your Xcode project.
#include <libxml2/libxml/parser.h>
#include <libxml2/libxml/tree.h>
can include Libxml
[CPP]View Plaincopy
- < span class= "keyword" style= "margin:0px; padding:0px; Border:none; Color:rgb (0,102,153); Background-color:inherit; Font-weight:bold ">void cblibxmlutility::savewithlibxml (Map<string,string>& data, const string& filename)
- {
- // create xml document &NBSP;&NBSP;
- " 1.0 "
- " cloudboxroot "
- //set Root
- Xmldocsetrootelement (Doc,root);
- for (map <string,string>::iterator iter = data.begin (); iter != data.end (); iter++)
-
- " key: " <<iter->first<<
- 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)
-
- " Create a xml: " <<NREL<< " bytes " <<ENDL;&NBSP;&NBSP;
- //debuglog (" create a xml %d bytes\n ", NRel); &NBSP;&NBSP;
- }
- //release
- Xmlfreedoc (DOC);
- }
This piece of code is a simple example , the data in the map data structure is saved to XML.