PDA

View Full Version : QT and XML



eltecprogetti
14th March 2012, 16:45
I want to read the contents of a XML file. This in my code:


QDomDocument doc("mydocument");
QFile file("CHOIX_DE_LA_CATEGORIE.xml");

if (!file.open(QIODevice::ReadOnly))
return;

if (!doc.setContent(&file))
{
file.close();
return;
}

file.close();

QDomElement docElem = doc.documentElement();

QDomNode n = docElem.firstChildElement("ss:Worksheet");

if (!n.isNull() && n.isElement())
{
QDomElement e = n.toElement();
ui->listWidget->addItem(e.text());
}


When I execute the program, in then listWidget is added a single line with all the contents of my file!! All the file in a single line without space.

Why???

How can I read from the file the single elements, the single fields?

mentalmushroom
15th March 2012, 11:31
try
e.nodeName()

wysota
15th March 2012, 12:32
What is the structure of the file?