Nominate our 2022 Qt Champions!

Performance Issue - Reading XML Values with 50-70 entry.

  • Hi,

    I want to read the values from the reg.xml file. I tried in several methods using FirstChild.NodeValue()/NextSibling.Nodevalue/NextSiblingbyelements etc.,
    The working code is down below. But the code seems to be lengthy and suspect some thing shortcut must be there to extract the values.
    Not like converting to QNodeList,assisgn to domNode and again Qstring.

    Is this code is right, Since If 50-70 xml enteries there, Then there will be performance issue. Kindly suggest.


    <?xml version="1.0" encoding="UTF-8"?>
        <Maps MapSysID="0">
            <description>General map - 1 used for testing including thumbnail</description>
            <created>Wed Aug 31 09:38:49 2016 GMT+0100</created>
            <modified>Wed Aug 31 09:56:07 2016 GMT+0100</modified>
            <EntryDate>Tuesday, October 04, 2016</EntryDate>
        <Maps MapSysID="1">
            <description>CAR map-2 for testing purpose</description>
            <created>Wed Aug 31 09:52:23 2016 GMT+0100</created>
            <modified>Wed Aug 31 09:54:59 2016 GMT+0100</modified>
            <EntryDate>Tuesday, October 04, 2016</EntryDate>

    C++ code for reading the xml

            QDomNodeList objQDomNodeListOne = docElem.elementsByTagName("Maps");
            QDomNode objQDomNodeone =;
            int intDomNode = objQDomNodeListOne.count();
            QString strTitle ;
            QString strItemId ;
            QString strDescription;
            QString strCreated ;
            QString strModified ;
            QString strOwner ;
            QString strUrl  ;
            QString strThumbnailUrl;
            QString strSize;
            QString strIsActive;
            QString strEntryDate;
            for(int i = 0; i < objQDomNodeListOne.count(); i++)
                   QDomNode elm =;
                       QDomElement e = elm.toElement();
                        QDomNodeList qNdlstTitle = e.elementsByTagName("Title");
                        QDomNodeList qNdlstitemId = e.elementsByTagName("itemId");
                        QDomNodeList qNdlstdescription = e.elementsByTagName("description");
                        QDomNodeList qNdlstcreated = e.elementsByTagName("created");
                        QDomNodeList qNdlstmodified = e.elementsByTagName("modified");
                        QDomNodeList qNdlstowner = e.elementsByTagName("owner");
                        QDomNodeList qNdlsturl = e.elementsByTagName("url");
                        QDomNodeList qNdlstthumbnailUrl = e.elementsByTagName("thumbnailUrl");
                        QDomNodeList qNdlstsize = e.elementsByTagName("size");
                        QDomNodeList qNdlstIsActive = e.elementsByTagName("IsActive");
                        QDomNodeList qNdlstEntryDate = e.elementsByTagName("EntryDate");
                        QDomNode qNodeTitle =;
                        QDomNode qNodeitemId =;
                        QDomNode qNodedescription =;
                        QDomNode qNodecreated =;
                        QDomNode qNodemodified =;
                        QDomNode qNodeowner =;
                        QDomNode qNodeurl =;
                        QDomNode qNodethumbnailUrl =;
                        QDomNode qNodesize =;
                        QDomNode qNodeIsActive =;
                        QDomNode qNodeEntryDate =;
                         strTitle  = qNodeTitle.firstChild().nodeValue();
                         strItemId = qNodeitemId.firstChild().nodeValue();
                         strDescription  = qNodedescription.firstChild().nodeValue();
                         strCreated = qNodecreated.firstChild().nodeValue();
                         strModified  = qNodemodified.firstChild().nodeValue();
                         strOwner = qNodeowner.firstChild().nodeValue();
                         strUrl  = qNodeurl.firstChild().nodeValue();
                         strThumbnailUrl = qNodethumbnailUrl.firstChild().nodeValue();
                         strSize  = qNodesize.firstChild().nodeValue();
                         strIsActive = qNodeIsActive.firstChild().nodeValue();
                         strEntryDate  = qNodeEntryDate.firstChild().nodeValue();

    Edit: Added code tags - p3c0

  • Moderators

    @Mathan-M Instead of QDom* you can use the QXmlStreamReader as the document says it is quite faster and memory efficient.
    Once you get to the parent node you can just use name and readElementText iteratively.