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函数的实现,因为以下这一段证明了它的重要性和强大的能力 ...
随机推荐
- Bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 最短路,floyd
1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 5 ...
- Linux I2C设备驱动编写(三)-实例分析AM3359
TI-AM3359 I2C适配器实例分析 I2C Spec简述 特性: 兼容飞利浦I2C 2.1版本规格 支持标准模式(100K bits/s)和快速模式(400K bits/s) 多路接收.发送模式 ...
- C标准库简单解读
1,程序运行时动态链接共享库; libc(character),libm(math),使用标准库的函数; eg:stdlib.h exit(); size_t数据类型,NULL空指针在头文件stdde ...
- Binggo公开课 “CODEX创新体系”的实战演练-中关村创业大街
Binggo公开课 "CODEX创新体系"的实战演练-中关村创业大街 Binggo公开课 "CODEX创新体系"的实战演练
- spring集成guava的event bus
Guava的event bus guava, https://github.com/google/guava 是一个非常有名的Java类库,提供了很多在日常开发中常用的集合.函数接口等.此外,guav ...
- Codeblocks + opencv + Cmake + minGW 环境搭建(一劳永逸版)
应工作开发需要,今天搭建一个codeblocks的C++开发环境,需要配置opencv2.4.4的API协同开发. 1.为了避免不必要的配置编译器,下载codeblocks16.1带mingw编译器版 ...
- js模板引擎实现原理
将html模板放入script标签中 // "> // ]]> 使用javascript开始解析模板 // )[^\t]*)'/g,"$1\r"). repl ...
- jetty服务器
1,http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin 2,http://wiki.eclipse.org/Jetty#Getting_S ...
- ABAP提示信息对话框
1. call function 'POPUP_TO_CONFIRM_WITH_MESSAGE' exporting diagnosetext1 = '数据为 ...
- Title Case
地址:http://www.codewars.com/kata/5202ef17a402dd033c000009/train/python 题目: A string is considered to ...