PDA

View Full Version : xml - get number of columns



wind
28th October 2006, 22:25
My XML looks like this:


<row>
<column name="name">c1</column>
<column name="address">c2</column>
</row>
<row>
<column name="name">c11</column>
<column name="address">c22</column>
</row>


Is there any easy way to get the numbers of columns in a row?
btw: The number of columns is in all rows the same.

wysota
28th October 2006, 22:30
I don't know if I understand the problem correctly, but how about this:


QDomElement rowelement;
int columncount = 0;
for(QDomElement colelement = rowelement.firstChildElement("column");
!colelement.isNull();
colelement = colelement.nextSiblingElement("column")
)
columncount++;
qDebug("Column count is %d", columncount);

jpn
28th October 2006, 22:32
Take a look at QtXml module (http://doc.trolltech.com/4.2/qtxml). A few XML examples are shipped with Qt, and there are short pieces of example code in the docs as well: QDomDocument, QDomElement..

wind
1st November 2006, 10:38
int columns = xml_doc.documentElement().firstChild().firstChildE lement().childNodes().count();