• 如何在iOS中使用libxml


    本文转载至 http://blog.csdn.net/cloudhsu/article/details/8087628

    1. 选择xcode工程设定

    2. 选择target

    3. 选择Summary

    4. 拉到Linked Frameworks and Libraries的地方,按下+按键

    输入libxml并选择libxml2,按下Add按键

    如此便可在工程中看到libxml2.dylib

    如同第一张图中,改选到Build Setting

    往下拉找到Search Paths在里面找到Header Search Paths

    开启编辑,并按下+然后输入${SDK_ROOT}/usr/include/libxml2

    如此一来便可在xcode项目中使用libxml了

    #include <libxml2/libxml/parser.h>

    #include <libxml2/libxml/tree.h>

    便可include libxml

    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.   
    7.     //set root  
    8.     xmlDocSetRootElement(doc,root);  
    9.   
    10.     for(map<string,string>::iterator iter = data.begin(); iter != data.end(); iter++)  
    11.     {  
    12.         cout<<"key:"<<iter->first<<"   value:"<<iter->second<<endl;  
    13.         xmlNewTextChild(root, NULL, BAD_CAST (*iter).first.c_str(), BAD_CAST (*iter).second.c_str());  
    14.     }  
    15.   
    16.     //save xml  
    17.   
    18.     int nRel = xmlSaveFile(fileName.c_str(),doc);  
    19.   
    20.     if (nRel != -1)  
    21.     {  
    22.         cout<<"create a xml:"<<nRel<<"bytes"<<endl;  
    23.         //DebugLog("Create a xml %d bytes ",nRel);  
    24.     }  
    25.   
    26.     //release  
    27.   
    28.     xmlFreeDoc(doc);  
    29. }  


    这段代码是一段简单的范例,将map数据结构中的数据保存到xml中。

    其他关于libxml的使用请参照我之前的文章"libxml教程"

    范例代码下载

  • 相关阅读:
    Filecoin:一种去中心化的存储网络(二)
    Filecoin:一种去中心化的存储网络(一)
    HTTP
    数据结构中的查找
    剑指offer-高质量的代码
    C++中STL容器的比较
    PBFT算法的相关问题
    springmvc最全约束
    springmvc入门(一)
    spring入门(一)
  • 原文地址:https://www.cnblogs.com/Camier-myNiuer/p/3791383.html
Copyright © 2020-2023  润新知