简体   繁体   中英

Print item from QDomNodeList with QT

I've called NYT xml url: http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml

and i received 39 records that I put in QDomDocument. So how to get the properties from single item ? This is my code but don't work, print empty.

QDomDocument doc;
    doc.setContent(reply->readAll());
    QDomNodeList list = doc.elementsByTagName("item");

    qDebug() << "Count" << list.count(); //this list get 39 items from url

    for (int i = 0; i < list.size(); i++) {
        qDebug() << list.at(i).attributes().namedItem("title").nodeValue();
    }

can you help me ?? Thanks

It doesn't look like attribute. It is an element.

    QDomDocument doc;
    doc.setContent(reply->readAll());
    QDomNodeList list = doc.elementsByTagName("item");
    qDebug() << "Count" << list.count(); //this list get 39 items from url
    for (int i = 0; i < list.size(); i++)
    {
        QDomElement first_title = list.at(i).toElement().firstChildElement("title");
        qDebug() << first_title.text();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM