I need to change some element attributes of a xml file. I've been trying to achieve this using QXmlStreamWriter class, but it does not work fine, because when I call the function, all elements are deleted of the xml file, except the changed attribute.
For example, I want to change the width of a rectangle, in a SVG file, keeping the other elements and attributes intact.
Here is my code:

Qt Code:
  1. void Editor::changeElementAttribute(int pos, QVariant newData)
  2. {
  3. DomItem *item = static_cast<DomItem*>(treeView->currentIndex().internalPointer());
  4. QDomNode node = item->node();
  5. QDomNamedNodeMap attributeMap = node.attributes();
  6.  
  7. file.setFileName(currentPath);
  8.  
  9. if (!file.open(QFile::WriteOnly | QFile::Text))
  10. {
  11. QMessageBox::warning(new QWidget(), tr("SVG Editor"),
  12. tr("Cannot write file %1:\n%2.").arg(currentPath)
  13. .arg(file.errorString()));
  14. return;
  15. }
  16.  
  17. stream.setDevice(&file);
  18. stream.writeStartElement(node.nodeName()); //tagname
  19. stream.writeAttribute(attributeMap.item(pos).nodeName(), newData.toString()); //attribute and value
  20. stream.writeEndElement();
  21. }
To copy to clipboard, switch view to plain text mode 

Any help is welcome.
Thanks in advanced!