Thanks. The following code does update the xml file now. However, it duplicates the content.
QFile file;
file.setFileName("autocal.xml");
file.open(QIODevice::ReadWrite | QIODevice::Text);
QDomDocument doc("autocal");
doc.setContent(file);
//do some reading here
QDomNodeList list = doc.elementsByTagName("calibrationOptions");
QDomNode parent = list.at(0);
QDomNode n = parent.firstChild();
if (n.isElement() && n.nodeName()=="camera")
{
QDomElement e = n.toElement();
e.setAttribute("value", "1");
}
QTextStream stream(file);
doc.save(stream, 4);
file.close();
--------------------------------------------------------------------------------------
Do I have to open the file twice like below (first time readonly, second time writeonly)?
QFile file;
file.setFileName("autocal.xml");
file.open(QIODevice::ReadOnly | QIODevice::Text);
QDomDocument doc("autocal");
doc.setContent(file);
file.close();
//do some reading here
QDomNodeList list = doc.elementsByTagName("calibrationOptions");
QDomNode parent = list.at(0);
QDomNode n = parent.firstChild();
if (n.isElement() && n.nodeName()=="camera")
{
QDomElement e = n.toElement();
e.setAttribute("value", "1");
}
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream stream(file);
doc.save(stream, 4);
file.close();
Bookmarks