Edit Value of a QDomElement?

Viewed 25294

I need to edit the text of a QDomElement - Eg

I have an XML file with its content as -

<root>    
    <firstchild>Edit text here</firstchild>
</root>

How do I edit the text of the child element <firstchild>?

I don't see any functions in the QDomElement of QDomDocument classes descriptions provided in Qt 4.7

Edit1 - I am adding more details.

I need to read, modify and save an xml file. To format of the file is as below -

<root>    
    <firstchild>Edit text here</firstchild>
</root>

The value of element needs to be edited.I code to read the xml file is -

QFile xmlFile(".\\iWantToEdit.xml");
xmlFile.open(QIODevice::ReadWrite);

QByteArray xmlData(xmlFile.readAll());

QDomDocument doc;
doc.setContent(xmlData);

// Read necessary values

// write back modified values?

Note: I have tried to cast a QDomElement to QDomNode and use the function setNodeValue(). It however is not applicable to QDomElement.

Any suggestions, code samples, links would we greatly welcome.

6 Answers
Here is Solution to update xml tag using QdomDocument,It's work for linux ubuntu 18.04  
 steps is open xmlfile in readwrite mode, setContent of file in object of qdomdocument,update node value, save xmlfile and close xmlfile.

        QString filepath= QDir::homePath() + "/Book.xml";
        QFile file (filepath);
        file.open(QIODevice::ReadWrite);
        QDomDocument doc;
        doc.setContent(&file); doc.documentElement().firstChildElement("BookPrice").firstChild().setNodeValue(QString("$7777"));
         file.resize(0);
         QTextStream stream;
         stream.setDevice(&file);
         doc.save(stream, 4);
         file.close();
Related