I'm trying to input data from an XML file in a C++ program using the Qt tool kit. My XML data is formatted as follows:
`<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>`
Currently the function that I have to read in the XML is as follows. Unfortunately it recognizes the data from the first tag (the title) and then returns all future attempts to access the data as NULL. The subRoot that I pass in is the domDocument.documentElement(). I am brand new to XML and somewhat new to Qt, and would appreciate any help you could offer in solving my problem! Thank you very much.
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;
}
}
}