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函数的实现,因为以下这一段证明了它的重要性和强大的能力 ...
随机推荐
- Naive and Silly Muggles
Problem Description Three wizards are doing a experiment. To avoid from bothering, a special magic i ...
- linux 多线程基础2
6. 名称:: pthread_detach 功能: 使线程进入分离状态. 头文件: #include <pthread.h> 函数原形: int pthread_detach(pthre ...
- ubuntukylin(64bit)安装推荐
UbuntuKylin是Ubuntu社区中面向中文用户的Ubuntu衍生版本,与麒麟系统没有关系.它是由工信部软件.集成电路促进中心(CSIP).国防科技大学(NUDT)与国际著名开源社区UBUNTU ...
- itunes备份文件解析入门
itunes提供给设备备份的功能,不知道怎么备份的话可以戳一下这个看一下:http://jingyan.baidu.com/article/92255446ea8f46851648f4a4.html ...
- .net 码农转战 iOS - 初探
好久没写博客了,之前还打算把毕业设计中涉及到的两个算法拿出来说说(脸型分析 + 声音分析),博文都写了一半了,后来实在太忙了,那篇随笔也就沉在草稿列表中没动过. 我原先是专职 .net 开发的,在公司 ...
- ubuntu 交换ctrl与caps lock 键
The relevant option is no longer available in the settings menu in Ubuntu 13.10; this has been repor ...
- 手动进行Excel数据和MySql数据转换
今天是全国数学建模比赛,同学选的一个题目需要对一个large的Excel表格进行统计,好哥们儿嘛--便帮助他完成了数据从Excel到MySql的转化.记下具体步骤分享给大家,也免得大家到网上到处乱找了 ...
- ActiveMQ入门实例(转)
1.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/ 2.运行ActiveMQ 解压缩apache-activemq-5.5.1-bin.zip,然后双击a ...
- .net互转java 转行必备
.net与java其实是差不多的语言,学习起来只需要弄清楚差异及查库的方法,转起来还是很快的 以下列出几点,希望能给正在转行的你一些帮助 1,java与c#语言超详细对比 http://www.har ...
- myeclipse building workspace如何禁止及提高myeclipse速度
大家一定对building workspace时那缓慢的速度给困扰到了吧~ 其实只要把project选项里的 building automatically前的勾去掉,就可以快很多了.. 另外大家一定对 ...