QDomDocument doc; doc.setContent(""); QDomElement root = doc.documentElement(); QDomNodeList books = root.elementsByTagName("book"); for (int i = 0; i < books.count(); ++i) { QDomNode book = books.at(i); if (book.isElement()) { qDebug() << "Book #" << i+1 << "is an element node"; } } Harry Potter
void print(QDomNode node) { if (node.isElement()) { qDebug() << "Element node: " << node.nodeName(); } else { qDebug() << "Non-element node: " << node.nodeName(); } for (QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling()) { print(child); } } QDomDocument doc; doc.setContent("This example defines a recursive function 'print' that prints the type and name of each node in the DOM tree. The function uses the isElement() method to distinguish between element and non-element nodes. We call the function on the root element of an XML document. The QDomNode class is part of the Qt Core module, which is included in the Qt library. It provides a comprehensive set of classes for creating graphical user interfaces, network communications, file handling, and other common tasks in C++ programming."); QDomNode root = doc.documentElement(); print(root); text