You are not logged in.

1

Thursday, September 29th 2011, 8:58am

How can change XML node value?

Hi all,

I have a xml file such as:
<config>
<lm>100</lm>
</config>

How can i update 100 to new value such as 50?

I can get 100 from file using QDomDocument, QDomNode, QDomElement classes and QDomElemet::text method.
But i can not update file. How can i do that? which class or function should i use to update <lm>100</lm> to </lm>50</lm>?

2

Thursday, September 29th 2011, 1:24pm

you have to use void QDomNode::save ( QTextStream & str, int indent ) const method..

example :

QDomNode* node = .... // retrieve the node you want to edit..
QByteArray data;
QTextStream ts(&data);

node->firstChildElement("mytag").save(ts, 2);