I want to replace a value of a xml tag. I can replace the value by using QDom, however I am getting a change in my xml file just after that change.
I am working with qt and I have tried with "QDOM" to replace the tag value and save it using "QTextStream".
QFile myFile(QLatin1String(my_FILE));
if (liceFile.open(QIODevice::ReadWrite)) {
QDomDocument doc;
doc.setContent(&myFile);
QDomElement parentEle = doc.firstChildElement("Root");
QDomNode myValue= parentEle.firstChildElement("Mytag");
myValue.firstChild().setNodeValue("Hey");
QTextStream stream(&myFile);
doc.save(stream, 4);
myFile.close();
The xml file
"<Root>
<Mytag>Hello</Mytag>
<User>Mr</User>
<Pass>121</Pass>"
If I replacing the value of "Mytag".
Output after replace.
"<Root>
<Mytag>Hey</Mytag>
<User/>
<Pass>121</Pass>"
I can not understand why <user> tag changed from "<User>Mr<User/>" to "<User/>"
Aucun commentaire:
Enregistrer un commentaire