为什么使用tinyxml2-ex ::文本返回损坏的文本?
我正在尝试使用 tinyxml2-ex
读取一些库来阅读一些库XML数据。
当我尝试使用它的特定API调用时:
const CString strNameToUse(tinyxml2::text(pAssign).c_str());
结果字符串会失去口音之类的东西。最后,我通过UTF8处理恢复了我的原始方法:
const CString strNameToUse(CA2CT(pAssign->GetText(), CP_UTF8));
这很好。有人知道为什么tinyxml2-ex :: text
方法失败了吗?请注意,使用tinyxml2
名称空间是允许使用的。
引用库的是std :: String
,并且这样做:
// helper function to get element text as a string, blank if none
inline std::string text (const XMLElement * element)
{
if (!element)
throw XmlException ("null element"s);
if (auto value = element -> GetText())
return std::string (value);
else
return ""s;
}
I am trying to use the tinyxml2-ex
library to read some XML data.
When I try using it's specific API call:
const CString strNameToUse(tinyxml2::text(pAssign).c_str());
The resulting string loses things like accents. In the end I have reverted to my original approach with the UTF8 handling:
const CString strNameToUse(CA2CT(pAssign->GetText(), CP_UTF8));
This works fine. Does anyone know why the tinyxml2-ex::text
approach fails? Note that it is permissible to the use the tinyxml2
namespace.
The referred to library is using std::string
and does it like this:
// helper function to get element text as a string, blank if none
inline std::string text (const XMLElement * element)
{
if (!element)
throw XmlException ("null element"s);
if (auto value = element -> GetText())
return std::string (value);
else
return ""s;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
图书馆作者解释说(github
The library author explained (GitHub discussion: