2
Qtツールキットを使用してC++プログラムでXMLファイルからデータを入力しようとしています。私のXMLデータは次のようにフォーマットされています:Qt 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で読み込む必要がある機能は次のとおりです。残念ながら、最初のタグ(タイトル)からのデータを認識し、その後、すべてのデータへのアクセス試行を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に慣れていないと言いました! –