QDomDocument doc; doc.setContent(""); QDomElement child = doc.documentElement().firstChildElement(); QDomElement parent = child.parentNode(); qDebug() << parent.tagName(); // should output "root"
QDomDocument doc; doc.setContent("In this example, we create a QDomDocument object and set its content to an XML structure with two child elements. Then we get the first child element of the root element and its next sibling element. We call the parentNode function on both child elements, which returns the same root element. Overall, the QDomElement parentNode function is very useful for navigating the tree-like structure of XML documents."); QDomElement child1 = doc.documentElement().firstChildElement(); QDomElement child2 = child1.nextSiblingElement(); QDomElement parent1 = child1.parentNode(); QDomElement parent2 = child2.parentNode(); qDebug() << parent1.tagName(); // should output "root" qDebug() << parent2.tagName(); // should output "root"