gpt4 book ai didi

c++ - TinyXml : Read wstring from XML file

转载 作者:行者123 更新时间:2023-11-28 03:29:49 25 4
gpt4 key购买 nike

unicode 字符又一次引起了严重的头痛。这是我正在尝试做的事情:1)我正在将 Sqlite 表(包括 unicode 字符)导出到 xml 文件(效果很好,unicode 字符不会丢失)2) 尝试在编辑这些 XML 表后再次导入它们 - 工作正常但 unicode 字符丢失。

读取xml文件的代码如下:

wstring input;
TiXmlElement* root = doc.FirstChildElement();
// count number of rows in xml file
TiXmlElement* counter = root->FirstChildElement();
int totalRows = 0;

while(counter != NULL) {
totalRows += 1;
counter = counter->NextSiblingElement();
}

// import data
wchar_t firstChar;
int check, length;
wstring finalInput;
TiXmlElement* rowElement = root->FirstChildElement();
for (int a = 1; a <= totalRows; a++) {
TiXmlElement* columnElement = rowElement->FirstChildElement();
// clear insert statement
insert = start;

for (int b = 1; b <= columns; b++) {
node = columnElement->FirstChild();
text = node->ToText();
// !!! here we have the problem data gets imported as a string !!!
input = text->Value();

问题是 Value(); (来自 tinyxml 文件的函数)返回 const char* 而不是 const wchar_t。我试图修改 TinyXml 文件以返回 wchar_t,但这导致了一些严重的错误。

我现在的问题是:有人知道如何使用 tinyxml 从 xml 文件中读取数据而不丢失 unicode 字符吗?

提前致谢,我们一如既往地非常感谢您的帮助。

最佳答案

我有 tinyxml2 库的 wchar_t(或 WCHAR)版本(我为我的项目转换了它)

http://pastebin.com/VrgNknaa.cpp

http://pastebin.com/NEy2jjM0.h

关于c++ - TinyXml : Read wstring from XML file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12896846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com