QDomDocument doc; QString xmlString = ""; doc.setContent(xmlString); QDomElement root = doc.documentElement(); QDomElement foo = root.namedItem("foo").toElement(); QString value = foo.text(); //returns "Bar" Bar Qux
QDomDocument doc; QString xmlString = "In both examples, we first create a QDomDocument object and set its content using an XML string. We then get the root element of the document and use the namedItem() method to find the child element with the desired name. Finally, we extract the text value of the element using the text() method. The QDomElement class belongs to the Qt Core Module library, which is included by default in Qt applications."; doc.setContent(xmlString); QDomElement root = doc.documentElement(); QDomElement foo = root.namedItem("foo").toElement(); QDomElement bar = foo.namedItem("bar").toElement(); QString value = bar.text(); //returns "Baz" Baz