Niamita
13th September 2011, 07:05
Hi all
I am reading a xml file but i am not successing in reading it. My code for reading file is
Xmlhandler::Xmlhandler(QTableWidget *table)
{
tablewidget = table;
table_item = 0;
}
bool Xmlhandler::startElement(const QString &, const QString &, const QString &qName,const QXmlAttributes &attributes)
{
if (qName == "statement"){
tablewidget->insertRow(1);
if(qName == "Condition")
{
QString str_id = attributes.value("text");
qDebug()<<str_id;
table_item = new QTableWidgetItem();
}
else if(qName == "action")
{
QString str_id = attributes.value("text");
qDebug()<<str_id;
table_item = new QTableWidgetItem();
}
else if(qName == "text")
currenttext.clear();
}
return true;
}
bool Xmlhandler::characters(const QString &str)
{
currenttext += str;
return true;
}
bool Xmlhandler::endElement(const QString &,const QString &,const QString &qName)
{
if(qName == "statement"){
if (qName == "Condition") {
if (qName == "page") {
table_item->setText(currenttext);
tablewidget->setItem(0, 0, table_item);
}
}
if (qName == "action") {
if (qName == "page") {
table_item->setText(currenttext);
tablewidget->setItem(0, 1, table_item);
}
}
}
return true;
}
bool Xmlhandler::fatalError(const QXmlParseException &exception)
{
QMessageBox::warning(0, QObject::tr("SAX Handler"),QObject::tr("Parse error at line %1, column "
"%2:\n%3.").arg(exception.lineNumber()).arg(exception.column Number()).arg(exception.message()));
return false;
}
and my xml file is like this-
<?xml version="1.0" encoding="UTF-8"?>
<statement>
<Condition id="1">
<text></text>
</Condition>
<action id="1">
<text></text>
</action>
</statement>
<statement>
<Condition id="2">
<text>Analog Input Equals to 1 END</text>
</Condition>
<action id="2">
<text>Digital Output Equals to ON END</text>
</action>
</statement>
i am trying to read xml and display it in a table.
Please guide me , i am doing this since three days but i am not getting desired result.
Thank you.
I am reading a xml file but i am not successing in reading it. My code for reading file is
Xmlhandler::Xmlhandler(QTableWidget *table)
{
tablewidget = table;
table_item = 0;
}
bool Xmlhandler::startElement(const QString &, const QString &, const QString &qName,const QXmlAttributes &attributes)
{
if (qName == "statement"){
tablewidget->insertRow(1);
if(qName == "Condition")
{
QString str_id = attributes.value("text");
qDebug()<<str_id;
table_item = new QTableWidgetItem();
}
else if(qName == "action")
{
QString str_id = attributes.value("text");
qDebug()<<str_id;
table_item = new QTableWidgetItem();
}
else if(qName == "text")
currenttext.clear();
}
return true;
}
bool Xmlhandler::characters(const QString &str)
{
currenttext += str;
return true;
}
bool Xmlhandler::endElement(const QString &,const QString &,const QString &qName)
{
if(qName == "statement"){
if (qName == "Condition") {
if (qName == "page") {
table_item->setText(currenttext);
tablewidget->setItem(0, 0, table_item);
}
}
if (qName == "action") {
if (qName == "page") {
table_item->setText(currenttext);
tablewidget->setItem(0, 1, table_item);
}
}
}
return true;
}
bool Xmlhandler::fatalError(const QXmlParseException &exception)
{
QMessageBox::warning(0, QObject::tr("SAX Handler"),QObject::tr("Parse error at line %1, column "
"%2:\n%3.").arg(exception.lineNumber()).arg(exception.column Number()).arg(exception.message()));
return false;
}
and my xml file is like this-
<?xml version="1.0" encoding="UTF-8"?>
<statement>
<Condition id="1">
<text></text>
</Condition>
<action id="1">
<text></text>
</action>
</statement>
<statement>
<Condition id="2">
<text>Analog Input Equals to 1 END</text>
</Condition>
<action id="2">
<text>Digital Output Equals to ON END</text>
</action>
</statement>
i am trying to read xml and display it in a table.
Please guide me , i am doing this since three days but i am not getting desired result.
Thank you.