Hello,
I'm trying to read all the values of a particular tag (in this case 'name') with in the xml file.
below is the actual xml file:
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<response>
<status>ok</status>
<project_list>
<project>
<id>1911</id>
<url>http://www.snipitron.com/arun/Qt_code</url>
<name>Qt code</name>
</project>
<project>
<id>1902</id>
<url>http://www.snipitron.com/arun/Mac_app</url>
<name>Mac app</name>
</project>
</project_list>
</response>
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<response>
<status>ok</status>
<project_list>
<project>
<id>1911</id>
<url>http://www.snipitron.com/arun/Qt_code</url>
<name>Qt code</name>
</project>
<project>
<id>1902</id>
<url>http://www.snipitron.com/arun/Mac_app</url>
<name>Mac app</name>
</project>
</project_list>
</response>
To copy to clipboard, switch view to plain text mode
And i'm having the Qt code to read the name value as below:
if (docElement.tagName() == "response"){
stat = docElement.firstChildElement("status").text();
statMsg = docElement.firstChildElement("message").text();
if (stat == "ok" ){
projNameNode = docElement.elementsByTagName("name");
for (uint j = 0; j < projNameNode.count(); j++)
{
nodeMsg = projNameNode.item(j).toElement().attribute("name");
}
}
} else
}
if (docElement.tagName() == "response"){
stat = docElement.firstChildElement("status").text();
statMsg = docElement.firstChildElement("message").text();
if (stat == "ok" ){
projNameNode = docElement.elementsByTagName("name");
for (uint j = 0; j < projNameNode.count(); j++)
{
nodeMsg = projNameNode.item(j).toElement().attribute("name");
QMessageBox::critical(this, "Arun", nodeMsg, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
}
}
} else
QMessageBox::critical(this, "Arun", "Status: " + stat + " Message: " + statMsg, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
}
To copy to clipboard, switch view to plain text mode
I'm missing something here and hence i'm getting NULL as value for nodeMsg.
any help is greatly appreciated.
thanks,
Ar
Bookmarks