我正在尝试使用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>`
Run Code Online (Sandbox Code Playgroud)
目前我必须在XML中阅读的功能如下.不幸的是,它识别来自第一个标签(标题)的数据,然后将所有将来访问数据的尝试都返回为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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
您的XML数据不是有效的XML - 反斜杠应该是正斜杠.例如:
<title>title<\title>
Run Code Online (Sandbox Code Playgroud)
应该:
<title>title</title>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2185 次 |
| 最近记录: |