Access elements of the xml-file
Hi, everyone!
I read the xml-file:
Code:
<Matrix>
<Description>
<rows>3</rows>
<columns>4</columns>
</Description>
<row1>
<cell>23.7</cell>
<cell>2.7</cell>
<cell>3.7</cell>
<cell>23.9</cell>
</row1>
<row2>
<cell>13.0</cell>
<cell>2.7</cell>
<cell>3.7</cell>
<cell>2</cell>
</row2>
<row3>
<cell>2.5</cell>
<cell>2.7</cell>
<cell>3.7</cell>
<cell>23.9</cell>
</row3>
</Matrix>
I want to write to the console these names of tags 'row1' and 'row2':
Code:
qDebug() << rowElement1.tagName();
qDebug() << rowElement2.tagName();
I expect to see:
But I see:
Code:
#include <QApplication>
#include <QFile>
#include <QTextStream>
#include <QDomDocument>
#include <QDomElement>
#include <QDomText>
#include <QMessageBox>
#include <QDebug>
#include <QObject>
int main(int argc, char **argv)
{
QFile file( "matrix.xml" );
{
return 0;
}
if( !document.setContent( &file ) )
{
file.close();
return 0;
}
file.close();
QDomElement matrixElement
= document.
documentElement();
QDomNode descriptionNode
= matrixElement.
firstChild();
QDomElement rowElement1
= descriptionNode.
nextSiblingElement();
qDebug() << rowElement1.tagName();
QDomElement rowElement2
= descriptionNode.
nextSiblingElement();
qDebug() << rowElement2.tagName();
app.exec();
}
Thanks!
Ivan
Re: Access elements of the xml-file
Code:
QDomElement rowElement2
= rowElement1.
nextSiblingElement();
qDebug() << rowElement2.tagName();
Re: Access elements of the xml-file