zoukankan      html  css  js  c++  java
  • c++:boost读取xml

    int   load(const std::string &strFilePath, const std::string &strFileName)
    {
    m_mapParam.clear();
    string strConfFullPath;
    if (kbdSuccess != makeConfigFileFullPath(strFilePath, strFileName, strConfFullPath))
    {
    return kbdFailed;
    }

    boost::property_tree::ptree pt;
    namespace xml = boost::property_tree::xml_parser;
    try
    {
    xml::read_xml(strConfFullPath, pt, xml::no_comments);
    BOOST_AUTO(module, pt.get_child("root"));
    for (BOOST_AUTO(pModuleIter, module.begin()); pModuleIter != module.end(); ++pModuleIter)
    {
    string strModuleName = pModuleIter->second.get<string>("<xmlattr>.name");
    boost::property_tree::ptree ptParam = pModuleIter->second;
    for (BOOST_AUTO(pParamIter, ptParam.begin()); pParamIter != ptParam.end(); ++pParamIter)
    {
    if (pParamIter->first == "param")
    {
    string strKey = pParamIter->second.get<string>("<xmlattr>.key");
    string strValue = pParamIter->second.get<string>("<xmlattr>.value");
    m_mapParam[strModuleName + CN_PARAM_SEPARATOR + strKey].push_back(strValue);
    }
    }
    }
    }
    catch (std::exception &ex)
    {
    LOGERROR("解析配置文件[%s]失败.Msg=[%s]", strConfFullPath.c_str(), ex.what());
    return1;
    }

    return 0;
    }

    不为其他,只为快乐!
  • 相关阅读:
    C语言实现快排
    C语言实现双向循环链表
    mysql插入数据后返回自增ID的方法
    golang flag包简单例子
    练习题 (六)
    练习题 (五)
    练习题 (四)
    练习题 (三)
    练习题 (二)
    练习题 (一)
  • 原文地址:https://www.cnblogs.com/1521299249study/p/10178596.html
Copyright © 2011-2022 走看看