olap74
3rd September 2016, 11:08
Hi,
I have a simple XML document, to test QtXML:
<?xml version = "1.0" encoding="UTF-8" standalone="yes" ?>
<player>
<name>John</name>
<informations>
<date format="JJ/MM/AAAA">31/08/2016</date>
<points>100</points>
</informations>
<name>Jack</name>
<informations>
<date format="JJ/MM/AAAA">31/08/2016</date>
<points>100</points>
</informations>
</player>
When I try to read the XML nodes, I can't leave the first child : <name>John
Below is the code :
if (m_xmlFile->open(QIODevice::ReadOnly)) {
if (!m_domDoc->setContent(m_xmlFile)) {
QDomElement dom_elt = m_domDoc->documentElement();
QDomNode noeud = dom_elt.firstChild();
// QDomNode n1 = dom_elt.parentNode();
QDomElement elt = noeud.toElement();
QString strElt;
if (!elt.isNull())
strElt = elt.tagName();
else
strElt="ERROR";
QMessageBox::information(this, "", strElt);
while (!noeud.isNull()) {
QMessageBox::information(this, "while", "...");
QDomElement noeud_element = noeud.toElement();
if(!noeud_element.isNull()) {
QMessageBox::information(this, "nom de la balise XML","noeud:"+noeud_element.tagName()
+";texte:"+noeud_element.text());
}
noeud.nextSibling();
}
}
}
the message information is always :
noeud: name;texte:john
infinite loop
Why the code doesn't go further ? What I have to add ?
thank you
I have a simple XML document, to test QtXML:
<?xml version = "1.0" encoding="UTF-8" standalone="yes" ?>
<player>
<name>John</name>
<informations>
<date format="JJ/MM/AAAA">31/08/2016</date>
<points>100</points>
</informations>
<name>Jack</name>
<informations>
<date format="JJ/MM/AAAA">31/08/2016</date>
<points>100</points>
</informations>
</player>
When I try to read the XML nodes, I can't leave the first child : <name>John
Below is the code :
if (m_xmlFile->open(QIODevice::ReadOnly)) {
if (!m_domDoc->setContent(m_xmlFile)) {
QDomElement dom_elt = m_domDoc->documentElement();
QDomNode noeud = dom_elt.firstChild();
// QDomNode n1 = dom_elt.parentNode();
QDomElement elt = noeud.toElement();
QString strElt;
if (!elt.isNull())
strElt = elt.tagName();
else
strElt="ERROR";
QMessageBox::information(this, "", strElt);
while (!noeud.isNull()) {
QMessageBox::information(this, "while", "...");
QDomElement noeud_element = noeud.toElement();
if(!noeud_element.isNull()) {
QMessageBox::information(this, "nom de la balise XML","noeud:"+noeud_element.tagName()
+";texte:"+noeud_element.text());
}
noeud.nextSibling();
}
}
}
the message information is always :
noeud: name;texte:john
infinite loop
Why the code doesn't go further ? What I have to add ?
thank you