How to use Libxml in iOS

Source: Internet
Author: User

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
  1. void Cblibxmlutility::savewithlibxml (map<string,string>& data,const string& fileName)
  2. {
  3. //Create XML document
  4. Xmldocptr doc = Xmlnewdoc (bad_cast"1.0");
  5. Xmlnodeptr root = xmlNewNode (null,bad_cast"Cloudboxroot");
  6. //set Root
  7. Xmldocsetrootelement (Doc,root);
  8. For (Map<string,string>::iterator iter = Data.begin (); ITER! = Data.end (); iter++)
  9. {
  10. cout<<"key:" <<iter->first<<"value:" <<iter->second<<endl;
  11. Xmlnewtextchild (Root, NULL, Bad_cast (*iter). First.c_str (), Bad_cast (*iter). SECOND.C_STR ());
  12. }
  13. //save XML
  14. int nRel = Xmlsavefile (Filename.c_str (), doc);
  15. if (nRel! =-1)
  16. {
  17. cout<<"Create a xml:" <<nRel<< "bytes" <<endl;
  18. //debuglog ("Create a XML%d bytes\n", NRel);
  19. }
  20. //release
  21. Xmlfreedoc (DOC);
  22. }


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.