zoukankan      html  css  js  c++  java
  • Poco XMLconfiguration 解析xml配置文件

    环境: Centos7

    GCC: 7.3.0

    准备需要读取的xml文件:

    <config>
        <prop1>1.23</prop1>
        <prop2>2.34</prop2>
        <prop3>
            <prop4 attr="1"/>
            <prop4 attr="2"/>
        </prop3>
        <prop5 id="first">hello,</prop5>
        <prop5 id="second"> world!</prop5>
    </config>

    创建需要解析的xml_config.cc

    #include<Poco/Util/AbstractConfiguration.h>
    #include<Poco/Util/XMLConfiguration.h>
    #include<iostream>
    
    using namespace std;
    using namespace Poco::Util;
    
    int main()
    {
        AbstractConfiguration * cfg = new XMLConfiguration("conf.xml");
        double prop1 = cfg->getDouble("prop1");
        double prop2 = cfg->getDouble("prop2");
        
        cout << "prop1 + prop2 = " << prop1 + prop2 << endl;
        cout << "This is an empty string: "
            << cfg->getString("prop3.prop4") << endl;
        int prop4 = cfg->getInt("prop3.prop4[@attr]");
        int prop4_0 = cfg->getInt("prop3.prop4[0][@attr]");
        int prop4_1 = cfg->getInt("prop3.prop4[1][@attr]");
        cout << "prop4 + prop4_0 + prop4_1 = "
            << prop4 + prop4_0 + prop4_1 << endl;
    
        cout << cfg->getString("prop5[0]")
               << cfg->getString("prop5[1]") << endl;
        cout << cfg->getString("prop5[@id='first']")
            << cfg->getString("prop5[@id='second']") << endl;
        return 0;
    }

    编译代码:

  • 相关阅读:
    商场活动|简单易用|可下载试用|复用转盘抽奖软件
    js dictionary
    财务大写
    SET ANSI_NULLS ON ……
    批量生成clr脚本
    Git
    CTE递归查询
    jquery 巧用json传参
    个人犯的一个golang routine错误
    .NET实现自动编译
  • 原文地址:https://www.cnblogs.com/Davirain/p/11591997.html
Copyright © 2011-2022 走看看