1

i have a problem with parsing an xml document using pugiXml, it seems to me that everything is correct but this code doesn't work :(

void MainWindow::open()
{
    QString fileName = QFileDialog::getOpenFileName(this,"Open");
    xml_document doc;
    doc.load_file(fileName.toStdString().c_str());

    for (pugi::xml_node node : doc.child("Person"))
    {
        qDebug(node.child_value("nom"));
        qDebug(node.child_value("Age"));
    }
}

Xml file format :

<?xml version="1.0"?>
<Persons>
<Person>
    <nom>Med</nom>
    <Age>12</Age>
</Person>
<Person>
    <nom>Nasr</nom>
    <Age>14</Age>
</Person>
<Person>
    <nom>Souad</nom>
    <Age>52</Age>
</Person>
</Persons>
1
  • 1
    What do you mean by "code doesn't work"? And as you are using Qt, why don't you use Qt's XML features? Commented Mar 28, 2013 at 19:21

1 Answer 1

2

The most probable cause is that you should use doc.child("Persons").

Document object in your case has one child Persons, that has several Person children. doc.child("Person") fails to find the node and returns a null handle.

Having said that, don't forget to check load_file return value as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.