QDomDocument doc; QFile file("xmlfile.xml"); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; if(!doc.setContent(&file)) return; QDomElement root = doc.documentElement(); QDomNodeList nodes = root.childNodes(); for(int i = 0; i < nodes.size(); i++) { QDomNode child = nodes.at(i); qDebug() << child.nodeName(); }
QDomDocument doc; QDomElement root = doc.createElement("root"); doc.appendChild(root); QDomElement child1 = doc.createElement("child1"); root.appendChild(child1); QDomElement child2 = doc.createElement("child2"); root.appendChild(child2); QDomElement child3 = doc.createElement("child3"); root.appendChild(child3); QDomNodeList nodes = root.childNodes(); for(int i = 0; i < nodes.size(); i++) { QDomNode child = nodes.at(i); qDebug() << child.nodeName(); }This code creates an XML document with a root element and three child elements. It then prints the name of each child element using the childNodes method. The QDomNode childNodes method is part of the Qt Core library.