Hi,
Im using QDomDocument for xml file.

My xml file has the following data,
Qt Code:
  1. <?xml version="1.0"?>
  2. <config>
  3. <dbus>
  4. <gas_value>2</gas_value>
  5. </dbus>
  6. </config>
To copy to clipboard, switch view to plain text mode 

I want to replace <gas_value>2</gas_value> with <gas_value>100</gas_value>

Im using following code to replace it
Qt Code:
  1. QFile *file = new QFile("dbus_write.xml");
  2.  
  3. if (!file->open(QIODevice::ReadWrite | QIODevice::Text))
  4. {
  5. qDebug() << "unable to open xml file";
  6. return;
  7. }
  8.  
  9. QDomDocument doc("dbus_write");
  10. doc.setContent(file);
  11.  
  12. QDomElement root = doc.firstChildElement("config");
  13. QDomElement parent = root.firstChildElement("dbus");
  14. QDomElement gasvalue = parent.firstChildElement("gas_value");
  15. parent.firstChildElement("gas_value").firstChild().setNodeValue("100");
  16. QTextStream stream(file);
  17. gasvalue.save(stream, 4);
  18. file->close();
To copy to clipboard, switch view to plain text mode 

but this code doesn't replaces the tag <gas_value>2</gas_value> , instead it creates another tag <gas_value>100</gas_value>
and produces following xml file
Qt Code:
  1. <?xml version="1.0"?>
  2. <config>
  3. <dbus>
  4. <gas_value>2</gas_value>
  5. </dbus>
  6. </config>
  7.  
  8. <gas_value>100</gas_value>
To copy to clipboard, switch view to plain text mode 

I tried using replaceChild() method, but results in same output.

Any thoughts?
thanks.