boost::xml————又一次失败的尝试
尝试使用wptree来进行xml解析,又一次失败了,可以正常读取正常输出,但是使用wptree进行节点读取失败(乱码)
请看源码:
DealXml.h
- #pragma once
- #include <string>
- #include <boost/property_tree/ptree.hpp>
- struct TestData
- {
- int var_int;
- std::string var_string;
- std::wstring var_wstring;
- };
- class DealXml
- {
- public:
- typedef boost::property_tree::ptree ptree_type;
- typedef boost::property_tree::wptree wptree_type;
- DealXml(void);
- ~DealXml(void);
- bool read_xmlW(std::basic_istream<wptree_type::key_type::value_type>& bis);
- bool write_xmlW(std::basic_ostream<wptree_type::key_type::value_type>& bos);
- bool open_file_and_read_xmlW(const std::string &filepath);
- bool open_file_and_write_xmlW(const std::string &filepath);
- private:
- ptree_type pt;
- wptree_type wpt;
- TestData m_TestData;
- };
DealXml.cpp
- #include "DealXml.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <boost/property_tree/xml_parser.hpp>
- #include <boost/property_tree/detail/xml_parser_flags.hpp>
- #include <boost/foreach.hpp>
- using namespace std;
- using namespace boost;
- DealXml::DealXml(void)
- {
- }
- DealXml::~DealXml(void)
- {
- }
- bool DealXml::read_xmlW(std::basic_istream<wptree_type::key_type::value_type>& bis)
- {
- bool is_success = false;
- do
- {
- try
- {
- boost::property_tree::xml_parser::read_xml(bis, wpt, boost::property_tree::xml_parser::no_concat_text|boost::property_tree::xml_parser::trim_whitespace);
- std::wstring wstr_test = wpt.get<std::wstring>(L"root.<xmlattr>.value");
- BOOST_FOREACH( wptree_type::value_type &v, wpt.get_child(L"root") )
- {
- if ( L"ceng1"==v.first )
- {
- //无法获取xml数据
- m_TestData.var_wstring = v.second.get_value<std::wstring>(L"ceng1");
- m_TestData.var_wstring = v.second.get_value<std::wstring>();
- //wchar_t *p = v.second.get_value<wchar_t*>(L"ceng1");
- //m_TestData.var_wstring = v.second.get<std::wstring>(L"ceng1");
- //m_TestData.var_int = v.second.get_value<int>(L"ceng1");
- //m_TestData.var_string = v.second.get_value<std::string>(L"ceng1");
- //std::cout << v.second.get_value<std::wstring>(L"ceng1") << std::endl;
- std::wcout << v.second.get_value<std::wstring>(L"ceng1") << std::endl;
- is_success = true;
- }
- }
- }
- catch(const std::exception &e)
- {
- std::cout << e.what() << std::endl;
- }
- } while (false);
- return is_success;
- }
- bool DealXml::write_xmlW(std::basic_ostream<wptree_type::key_type::value_type>& bos)
- {
- bool is_success = false;
- do
- {
- try
- {
- boost::property_tree::xml_parser::xml_writer_settings<wchar_t> settings(L'\t', , L"utf-8");
- boost::property_tree::xml_parser::write_xml<wptree_type>(bos, wpt, settings);
- }
- catch(const std::exception &e)
- {
- std::cout << e.what() << std::endl;
- }
- } while (false);
- return is_success;
- }
- bool DealXml::open_file_and_read_xmlW(const std::string &filepath)
- {
- bool is_success = false;
- do
- {
- try
- {
- std::basic_filebuf<wchar_t> bfb;
- if (bfb.open(filepath.c_str(), std::ios::in))
- {
- std::basic_istream<wchar_t> bis(&bfb);
- read_xmlW(bis);
- bfb.close();
- is_success = true;
- }
- }
- catch(const std::exception &e)
- {
- std::cout << e.what() << std::endl;
- }
- } while (false);
- return is_success;
- }
- bool DealXml::open_file_and_write_xmlW(const std::string &filepath)
- {
- bool is_success = false;
- do
- {
- try
- {
- std::basic_filebuf<wchar_t> bfb;
- if (bfb.open(filepath.c_str(), std::ios::out))
- {
- std::basic_ostream<wchar_t> bos(&bfb);
- write_xmlW(bos);
- bfb.close();
- is_success = true;
- }
- }
- catch(const std::exception &e)
- {
- std::cout << e.what() << std::endl;
- }
- } while (false);
- return is_success;
- }
boost::xml————又一次失败的尝试的更多相关文章
- 一次失败的尝试hdfs的java客户端编写(在linux下使用eclipse)
一次失败的尝试hdfs的java客户端编写(在linux下使用eclipse) 给centOS安装图形界面 GNOME桌面环境 https://blog.csdn.net/wh211212/artic ...
- boost::xml——基本操作以及中文乱码解决方案 (续)
本博文主要想说明以下两点: 1.对于上一篇的<boost::xml——基本操作以及中文乱码解决方案>解释,这篇博文基本解决了正确输入输出中英文问题,但是好像还没有解决修改中文出现乱码的问题 ...
- boost::xml——基本操作以及中文乱码解决方案
下面是本人使用boost库的xml部分的基础操作,并且解决对于大家使用boost库读写中文xml内容出现的乱码问题. 1.实现boost库xml基本操作2.解决boost对xml中中文乱码问题3.实现 ...
- 在java下面配置xml导致idea编译失败
1.今天遇到一个问题在java配置dao.xml的时候导致,idea编译失败 然后把pom.xml上面的 <build> <resources> <resource> ...
- springcloud-1: 用官方的pom.xml配置添加依赖失败
在eclipse中用STS生成了一个springcloud应用,pom.xml的核心配置如下: <parent> <groupId>org.springframework.bo ...
- LeetCode 失败的尝试 10. regular expression matching & 正则
Regular Expression Matching 看到正则就感觉头大,因为正则用好了就很强大.有挑战的才有意思. 其实没有一点思路.循环的话,不能一一对比,匹配模式解释的是之前的字符.那就先遍历 ...
- 失败的尝试,使用继承扩展数组,以及ES6的必要性
我们都知道直接在原生对象上扩展对象是很不好的.所以prototype这样的库广受非议. 一些库,比如lodash采用了工具包形式的扩展方式,绕开了对象的继承. 由于es6的class的出现,我尝试以A ...
- ubuntu 18.04下greenplum安装笔记(二)安装Greenplum的失败的尝试
之前对Linux环境进行了搭建,现在开始进行Greenplum的正式安装. 下载 进Greenplum的官网:https://greenplum.org/download/ 可以发现,对于ubuntu ...
- osgEarth开发之OSG解构——失败的尝试
概述 本文在吸收了<最长的一帧>以及相关参考资料的基础之上解读OSG的基础数据结构,渲染方法. 实现 在这第一部分里,要理解的是run函数的实现,因为以下这一段证明了它的重要性和强大的能力 ...
随机推荐
- 今天遇到的mouseout和mouseleave之坑
时间紧 简短的说就是: mouseout是离开其子元素也会触发 mouseleave是离开指定的那个元素才触发
- HTML页面规范
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title> ...
- Oracle 视图添加主键
在Entity Framework中,从数据库生成模型,视图常报无主键. 解决办法:为试图添加主键/复合主键 create or replace view view_activebudgetamoun ...
- node begining
node begining */--> pre { background-color: #2f4f4f;line-height: 1.6; FONT: 10.5pt Consola," ...
- 开发小技巧:C#逐个输出字符
静态自定义方法: static int counter = 0; static string displayString = "This string will appear one let ...
- Raspberry Pi Kernel Compilation 内核编译官方文档
elinux.org/Raspberry_Pi_Kernel_Compilation#Use_the_provided_compiler Software & Distributions: S ...
- 数字集成电路设计-8-一个简单sobel图像边缘检测加速器的设计,实现,仿真与综合
引言 图像视频处理等多媒体领域是FPGA应用的最主要的方面之一,边缘检测是图像处理和计算机视觉中的基本问题,所以也是最常用的,随着数据量的不断增加以及对实时性的要求,一般软件已经不能满足实际需要,这时 ...
- WinForm TextBox自定义扩展方法数据验证
本文转载:http://www.cnblogs.com/gis-crazy/archive/2013/03/17/2964132.html 查看公司项目代码时,存在这样一个问题:winform界面上有 ...
- oracle强化练习之分组函数
1. 显示平均工资为>2000的职位 select job,avg(sal) from emp group by job having avg(sal)>2500; 2. ...
- [ES7] Exploring ES2016 Decorators
Original artial --> link How descorator looks like: @mydecorator function myFun(){ ... } Descorat ...