This article reprinted to http://blog.csdn.net/cloudhsu/article/details/8087628
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
- 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 piece of code is a simple example of saving data in a map structure to XML.
Please refer to my previous article "Libxml Tutorial" for other uses of Libxml
Sample code Download