How to Use libxml in IOS

Source: Internet
Author: User
Tags map data structure
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

Related Article

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.