尝试使用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;
}

最新文章

  1. 浅谈Android应用保护(一):Android应用逆向的基本方法
  2. ZooKeeper个人笔记之节点的监听
  3. hadoop环境搭建
  4. IIS 6中mimemap属性的默认设置
  5. 小甲鱼python视频第十讲(课后习题)
  6. 十分钟搞懂什么是CGI
  7. 设计模式之Interator模式(1)
  8. QcheckBox
  9. Sublime Text 编辑器
  10. linux进程后台运行的几种方法
  11. Winform动态加载TabControl用法
  12. CI框架篇之类库篇--基础(1)
  13. bzoj2965
  14. Linux显示目前与过去登入系统的用户相关信息
  15. 洛谷 P2904 [USACO08MAR]跨河River Crossing
  16. 13点值得我们注意的谷歌的JavaScript编写风格
  17. 解决ssh登陆很慢的问题
  18. Linux - 变量的查看与设置
  19. Python3学习之路~5.3 random模块
  20. 对于“2017面向对象程序设计(JAVA)第四周学习总结”存在问题的反馈

热门文章

  1. [Boost]图形处理库Boost::Polygon
  2. Qualcomm 8X camera daemon进程浅析
  3. Yii PHP 框架分析(四)
  4. Morris Traversal 二叉树遍历。
  5. Excel文件上传
  6. [C#] 常用工具类——直接在浏览器输出数据
  7. 用JAX-WS在Tomcat中公布WebService
  8. HTTP 404 - 未找到文件 怎么样解决
  9. the Linux Kernel: Traffic Control, Shaping and QoS
  10. 固定ip