#include#include int main() { QDomDocument doc("mydocument"); QDomElement elem = doc.createElement("root"); QDomElement childElem = doc.createElement("child"); elem.appendChild(childElem); if (elem.hasChildNodes()) { qDebug() << "The root element has child nodes."; } else { qDebug() << "The root element does not have any child nodes."; } return 0; }
#includeIn this example, a new XML document is created using QDomDocument. Then, a text node is created with the value "Hello world!". The hasChildNodes method is then called on the text node to see if it has any child nodes. Since it is a leaf node and can't have any children, the output will be "The text node does not have any child nodes." Package library: Qt library.#include int main() { QDomDocument doc("mydocument"); QDomText textNode = doc.createTextNode("Hello world!"); if (textNode.hasChildNodes()) { qDebug() << "The text node has child nodes."; } else { qDebug() << "The text node does not have any child nodes."; } return 0; }