I'm trying to update a simple xml file without much success:
Qt Code:
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <system_desktop_icons>
  3. <trash>
  4. <pos>@Point(0, 50)</pos>
  5. <position>
  6. <x>0</x>
  7. <y>50</y>
  8. </position>
  9. </trash>
  10. </system_desktop_icons>
To copy to clipboard, switch view to plain text mode 


This is my code:
Qt Code:
  1. QFile inputFile ("/home/renan/xmlparser/desktopIconPosition.xml");
  2. if (!inputFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
  3. {
  4. qDebug() << "Failed to open file for reading.";
  5. return false;
  6. }
  7.  
  8. QDomDocument document;
  9. if (!document.setContent (&inputFile))
  10. {
  11. qDebug() << "Failed to parse the file into a DOM tree.";
  12. inputFile.close();
  13. return false;
  14. }
  15.  
  16. inputFile.close();
  17.  
  18. QDomElement documentElement = document.documentElement();
  19. QDomNodeList elements = documentElement.elementsByTagName ("trash");
  20.  
  21. if (elements.size() == 1)
  22. {
  23. QDomNode node = documentElement.firstChild();
  24. while( !node.isNull() )
  25. {
  26. if( node.isElement() )
  27. {
  28. QDomElement element = node.toElement();
  29. qDebug() << "ELEMENT" << element.tagName();
  30. qDebug() << "ELEMENT ATTRIBUTE NAME" << element.attribute( "name", "not set" );
  31.  
  32. }
  33.  
  34. if( node.isText() )
  35. {
  36. QDomText text = node.toText();
  37. qDebug() << text.data();
  38. }
  39.  
  40. node = node.nextSibling();
  41. }
  42. }
  43.  
  44. QFile outputFile ("/home/renan/xmlparser/desktopIconPosition.xml");
  45. if (!outputFile.open (QIODevice::WriteOnly | QIODevice::Text))
  46. {
  47. qDebug() << "Failed to open file for writing.";
  48. return false;
  49. }
  50.  
  51. QTextStream stream (&outputFile);
  52. stream << document.toString();
  53.  
  54. outputFile.close();
To copy to clipboard, switch view to plain text mode 

I want to change x and y values, but with this code I just get a qDebug output of trash. I never get the pos or position output.

I hope I was clear enough.

Any help?

Renan