Qt + parcours fichier xml
Bonjour,
je souhaite parcourir mon fichier xml pour recueillir des informations.
Mon fichier xml est de la forme
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
<historique>
<jour>
<date> </date>
<unHisto>
<url> </url>
<nom> </nom>
<heure> </heure>
</unHisto>
<unHisto>
<url> </url>
<nom> </nom>
<heure> </heure>
</unHisto>
</jour>
<jour>
<unHisto>
<url> </url>
<nom> </nom>
<heure> </heure>
</unHisto>
</jour>
</historique> |
J'enregistre dans mon fichier xml l'historique des pages visitées par l'utilisateur.
J'ai fais :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
QDomDocument doc;
QFile file("historique.xml");
file.open(QIODevice::ReadOnly);
doc.setContent(&file);
file.close();
QDomElement root = doc.documentElement();
QDomElement child = root.firstChild().toElement();
while(!child.isNull())
{
if (child.tagName() == "jour")
{
QDomElement grandChild = child.firstChild().toElement();
while(!grandChild.isNull())
{
if (grandChild.tagName() == "date")
{
QDomElement grandGrandChild = grandChild.firstChild().toElement();
while(!grandGrandChild.isNull())
{
if (grandGrandChild.tagName() == "unHisto")
{
QDomElement grandGrandGrandChild = grandGrandChild.firstChild().toElement();
while(!grandGrandGrandChild.isNull())
{
if (grandGrandGrandChild.tagName() == "url")
{
listeUrl << grandGrandGrandChild.text();
splitUrl(grandGrandGrandChild.text());
}
grandGrandGrandChild = grandGrandGrandChild.nextSibling().toElement();
}
}
grandGrandChild = grandGrandChild.nextSibling().toElement();
}
}
grandChild = grandChild.nextSibling().toElement();
}
}
} |
En fait, je souhaite mettre le contenu de mes balises <url> dans ma liste.
Ce parcours me parait un peu long parce que ça fait planter mon appli :p
Si quelqu'un à une idée ^^
Merci d'avance