Reading is easy (this example, I should probably close the file.... oops)
Qt Code:
  1. QString filename = "C:/test.xml";
  2. QFile file(filename);
  3. if (!file.open(QFile::ReadOnly | QFile::Text))
  4. {
  5. qDebug(qPrintable(QString("Error: Cannot read file %1 %2").arg(filename).arg(file.errorString())));
  6. return;
  7. }
  8. doc.setContent(&file);
To copy to clipboard, switch view to plain text mode 
Is your real concern related to processing? Consider this small example that traverses a DOM tree
Qt Code:
  1. void pp(QTextStream& os, QDomNode node)
  2. {
  3. while (!node.isNull())
  4. {
  5. if (node.isElement())
  6. {
  7. // Ignore attributes for now.
  8. //qDebug(qPrintable(QString("DEBUG: <%1>").arg(node.toElement().tagName())));
  9. os << "<" << node.toElement().tagName() << ">";
  10. if (node.hasChildNodes())
  11. {
  12. QDomNode childNode = node.firstChild();
  13. pp(os, childNode);
  14. }
  15. // Print all children
  16. //qDebug(qPrintable(QString("DEBUG: </%1>").arg(node.toElement().tagName())));
  17. os << "</" << node.toElement().tagName() << ">";
  18. }
  19. else if (node.isText())
  20. {
  21. os << node.toText().data();
  22. }
  23. else
  24. {
  25. qDebug(qPrintable(QString("Unexpected node type:")));
  26. //qDebug(qPrintable(QString("Unexpected node type: %1").arg((int)(node.NodeType()))));
  27. }
  28. node = node.nextSibling();
  29. }
  30. }
To copy to clipboard, switch view to plain text mode 
The example ignores attributes. The head node that I would pass as an argument is found using doc.documentElement().
This snippet copies a node out of a DOM tree and removes the node. I then insert the node in a different location.
Qt Code:
  1. QString xmlOriginal = "<xml><item><a>1</a></item><item><a>2</a></item></xml>";
  2. doc.setContent(xmlOriginal);
  3. QDomElement docElement = doc.documentElement();
  4. QDomNode firstChild = docElement.firstChild();
  5. QDomNode secondChild = firstChild.nextSibling();
  6. QDomNode clonedNode = secondChild.cloneNode(true);
  7. doc.documentElement().removeChild(secondChild);
  8. doc.documentElement().insertBefore(clonedNode, firstChild);
  9. QString s2;
  10. QTextStream os2(&s2);
  11. os2 << "\nStream *****\n" << doc;
  12. qDebug(qPrintable(s2));
To copy to clipboard, switch view to plain text mode