Important: Please read the Qt Code of Conduct -

Access XML nodes

  • Hi all,

    I have an XML of following structure:

    <?xml version="1.0"?>
     <Date>01/01/2000 00:00</Date>
     <Clinician_Note>note </Clinician_Note>

    I'm using QDomDocument to read.
    I can get individual node value by tagname, for ex:


    This gives me the Current node value 12

    What's the method to get all node values under Settings node?

    Thank you

  • Lifetime Qt Champion

    Often by simply enumerating the elements

    QDomNode n = docElem.firstChild();
    while(!n.isNull()) {
        QDomElement e = n.toElement(); // try to convert the node to an element.
        if(!e.isNull()) {
            cout << qPrintable(e.tagName()) << endl; // the node really is an element.
        n = n.nextSibling();

  • @russjohn834
    As @mrjj has said, QDomDocument basically wants you to walk the tree as necessary to visit things.

    There is to give you the list of children in one go instead of calling firstChild()/nextSibling() etc. But you'll still have to iterate through them if you want to see what's inside. You won't find a single "get all node values under node".

  • Thank you @mrjj , @JonB

Log in to reply