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 ...
- EF-CodeFirst-表关系-延迟/贪婪加载
表关系建立: http://blog.csdn.net/niewq/article/details/17232321 一对多: namespace LckLib.EF.V6.Models { publ ...
- DS1302-演示代码
参考DS1302数据手册,尽管数据手册是英文,但是很有帮助,再结合网上众多的代码写出了下面这个例子,除了涓流充电(trickle charger)功能没使用外,内部的RAM和寄存器功能都使用到了,包括 ...
- ios 中的半屏幕底部弹出框
static UIView *modalView;if (modalView) { [modalView removeFromSuperview]; modalView = nil; return; ...
- Yii Framework 开发教程Zii组件-Tabs示例
有关Yii Tab类: http://www.yiichina.com/api/CTabView http://www.yiichina.com/api/CJuiTabs http://blog.cs ...
- Shell if else语句
if 语句通过关系运算符判断表达式的真假来决定执行哪个分支.Shell 有三种 if ... else 语句: if ... fi 语句: if ... else ... fi 语句: if ... ...
- PyDev+eclipse的编码问题
1.在代码的开始声明编码为utf-8
- 5种Web常见编码、变换算法的自动识别
#coding=utf-8 #识别字符序列变换算法,当前支持标准的MD5.SHA-1.Base64,及主流的URL编码.HTML编码 import re import sys #MD5判断函数 def ...
- UIAlertController:弹框4步走
对于大多数的App来说,弹框这种交互方式基本上是必不可少的.在新的iOS系统中(具体版本我忘了),以前的UIAlertView被弃用,而换成了现在的UIAlertController. UIAlite ...
- 了解node.js
转载自http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef7-0f7ecbdd56cb 当我向人们介绍nod ...