pugixml读取unicode编码的xml文件的做法

作者:朱金灿

来源:http://blog.csdn.net/clever101

 

           实际上在多字节编码的情况下,即以记事本打开显示的ANSI编码的,如下图:

        pugixml是可以直接读取中文字符的,示例代码如下:


const std::string strFilePath = _T(“c:\xgconsole.xml”);

pugi::xml_document doc;

doc.load_file(strFilePath.c_str());

      

        所以之前我写的一篇文章《pugixml库的一个使用心得》的说法是不准确的。如果要读取unicode编码的xml文件,即以记事本打开显示的ANSI编码的,如下图:

则要使用下面方法读取:

const std::wstring strFilePath = _T(“c:\xgconsole.xml”);

pugi::xml_document doc;

doc.load_file(strFilePath.c_str(),pugi::parse_default,pugi::encoding_utf8);

         可以看出load_file函数的最后一个参数是可以指定xml文件的编码格式的。

原文地址:https://www.cnblogs.com/lanzhi/p/6470097.html