环境: 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;
}

编译代码:

Poco XMLconfiguration 解析xml配置文件的更多相关文章

  1. dom4j解析xml配置文件

    通过dom4j来对xml配置文件的增删查改: 利用@Test注解来对单个方法进行测试: import java.io.FileOutputStream; import java.io.OutputSt ...

  2. 使用XMLConfiguration解析xml,PropertiesConfiguration解析properties等相应信息

    org.apache.commons.configuration.XMLConfiguration; Apache Common-Configuration工具可以从Properties文件,XML文 ...

  3. dom4j解析XML的CURD操作

    在开发JavaWeb项目中通常是利用XML配置文件来提高应用程序的访问效率,而在配置XML的同时,更多时候是对XML进行解析. 一.解析XML配置文件有两种机制: DOM和SAX的机制: DOM是将整 ...

  4. Spring中 <context:property-placeholder 的使用与解析 .properties 配置文件的加载

    转: Spring中property-placeholder的使用与解析 Spring中property-placeholder的使用与解析 我们在基于spring开发应用的时候,一般都会将数据库的配 ...

  5. JQuery -- Jquery 中的Ajax, Jquery解析xml文件

    1. JQuery 对 Ajax 操作进行了封装,在 jQuery 中最底层的方法时 $.ajax(), 第二层是 load(), $.get() 和 $.post(),第三层是$.getScript ...

  6. Spring如何读取xml配置文件的

    我们通过一个小案例来看xml解析过程. 1. 导包 <dependencies> <!-- xml解析工具 --> <dependency> <groupId ...

  7. properties和XML配置文件内容的获取

    @ 目录 总结内容 1. Java中为什么要使用配置文件 2. Java中常用的配置文件类型有哪些以及它们的特点 Properties配置文件 XML配置文件 总结 总结内容 1. Java中为什么要 ...

  8. 使用JDom解析XML文档模拟Spring的配置文件解析

    在J2EE项目中可能会涉及到一些框架的使用,最近接触到了SSH,拿Spring来说配置文件的使用是相当重要的,Spring的配置文件是一个xml文件,Spring是如何读取到配置文件并进行依赖注入的呢 ...

  9. mybatis源码配置文件解析之五:解析mappers标签(解析XML映射文件)

    在上篇文章中分析了mybatis解析<mappers>标签,<mybatis源码配置文件解析之五:解析mappers标签>重点分析了如何解析<mappers>标签中 ...

随机推荐

  1. java多线程之Executor 与 ExecutorService两个基本接口

    一.Executor 接口简介 Executor接口是Executor框架的一个最基本的接口,Executor框架的大部分类都直接或间接地实现了此接口. 只有一个方法 void execute(Run ...

  2. Unity基础:AR(增强现实)的学习

    版权申明: 本文原创首发于以下网站: 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123 优梦创客的官方博客:https://91make.top ...

  3. 如何在Centos服务器上搭建起Oracle10、VNC、以及FTP

    一.重装和分区 1.配置所需磁盘阵列(Raid): 2.正确分区: 3.Centos安装:过于简单,请自行bd. 二.连网 系统安装完成之后,我们需为其分配IP和DNS: "编辑连接&quo ...

  4. Java验证手机号

    在实际开发中我们需要对手机号格式校验,以下是对中国手机号校验的实现. public class PhoneUtils { /** * 中国手机号码 */ private static Pattern ...

  5. Windows 7 上怎样打开SQL Server 配置管理器

    场景 在Windows 7 上打开 SQL Server 的配置管理器. 实现 右击电脑--管理 在计算机管理--服务和应用程序-SQL Server 配置管理器 注: 博客首页: https://b ...

  6. Find a way(两个BFS)

    Problem Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. L ...

  7. POJ - 3984 迷宫问题 (搜索)

    Problem Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, ...

  8. 强大的时间处理库 moment

    中文文档: http://momentjs.cn/docs/ 常用方法 1.当前时间对象  moment ()   /  指定时间对象  moment("2019-09-19 08:00:0 ...

  9. stm32 新建工程

    先新建六个文件夹. Consis:启动文件等 Fwlib:inc.src文件夹 Hardware:存放驱动 Mdk:工程文件 User:main函数等

  10. SpringBoot的注解注入功能移植到.Net平台(开源)

    *:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...