求助,在VC++中用什么解析xml
1个回答
展开全部
一般我用tinyxml解析,不过tinyxml不支持Unicode编码。然后再写一个wstring 转string 全局函数。函数如下:
std::string ws2s(const std::wstring& ws)
{
std::string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C";
setlocale(LC_ALL, "chs");
const wchar_t* _Source = ws.c_str();
size_t _Dsize = 2 * ws.size() + 1;
char *_Dest = new char[_Dsize];
memset(_Dest, 0, _Dsize);
size_t i;
// wcstombs_s(&i,_Dest, _Source, _Dsize);
wcstombs_s(&i, _Dest, _Dsize, _Source, _Dsize);// wcslen(_Source));
std::string result = _Dest;
delete[]_Dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
}
std::string ws2s(const std::wstring& ws)
{
std::string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C";
setlocale(LC_ALL, "chs");
const wchar_t* _Source = ws.c_str();
size_t _Dsize = 2 * ws.size() + 1;
char *_Dest = new char[_Dsize];
memset(_Dest, 0, _Dsize);
size_t i;
// wcstombs_s(&i,_Dest, _Source, _Dsize);
wcstombs_s(&i, _Dest, _Dsize, _Source, _Dsize);// wcslen(_Source));
std::string result = _Dest;
delete[]_Dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询