我正在尝试使用 Qt 工具包在 C++ 程序中从 XML 文件输入数据。我的 XML 数据的格式如下:
`<item>
<title>title<\title>
<tree_loc1>0<\tree_loc1>
<parent>parent<\parent>
<description>description<\description>
<other_info>other info<\other_info>
<location>location<\location>
<last_modified>Mar 28 2009 8:16 pm<\last_modified>
<radio>0<\radio>
</item>`
目前我必须在 XML 中读取的函数如下。不幸的是,它识别出第一个标签(标题)中的数据,然后将所有 future 访问该数据的尝试返回为 NULL。我传入的 subRoot 是 domDocument.documentElement()。我对 XML 很陌生,对 Qt 也有些陌生,非常感谢您在解决我的问题时提供的任何帮助!非常感谢。
void XmlHandler::readXML(QStandardItemModel *model, QDomNode subRoot){
QDomElement node;
QString title;
int row;
QString parent;
QString description;
QString other_info;
QString location;
QString last_modified;
QString radio;
QString value;
bool flag;
if (subRoot.isNull())
return; // error condition
for (int i = 0; i < N_STRINGS; i++){
node = subRoot.firstChildElement(tagName[i]); // returns NULL all but the 1st time
value = DEFAULT_VALUE;
value = node.text();
switch (i) {
case 0:
title = value;
break;
case 1:
row = value.toInt();
break;
case 2:
parent = value;
break;
case 3:
description = value;
break;
case 4:
other_info = value;
break;
case 5:
location = value;
break;
case 6:
last_modified = value;
break;
case 7:
radio = value;
break;
}
}
}
最佳答案
您的 XML 数据不是有效的 XML - 反斜杠应该是正斜杠。例如:
<title>title<\title>
应该是:
<title>title</title>
关于c++ - Qt XML 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/695515/