The Great Gatsby F. Scott Fitzgerald
QDomDocument doc; doc.setContent(xmlData); QDomElement root = doc.documentElement(); QDomElement title = root.firstChildElement("title"); QString titleText = title.toText().data(); qDebug() << titleText; // Output: "The Great Gatsby"
- apples
- bananas
- oranges
QDomDocument doc; doc.setContent(xmlData); QDomElement root = doc.documentElement(); QDomNodeList items = root.elementsByTagName("item"); QStringList itemTexts; for (int i = 0; i < items.size(); ++i) { QDomNode item = items.at(i); itemTexts.append(item.toText().data().trimmed()); } QString itemsText = itemTexts.join(", "); qDebug() << itemsText; // Output: "apples, bananas, oranges"In both examples, we use the QDomNode class provided by the Qt library for C++. This class is part of the Qt Core module.