c++ - Change attribute value of an XML tag in Qt -
i'm trying change language
attribute of .ts file in qt using qt itself.
here sample xml format.
<?xml version='1.0' encoding='utf-8'?> <!doctype ts> <ts language="es_es" version="2.1"> ... </ts>
i have tried different ways, no luck. here methods used.
fileioerror fileio::changelanguageoftsfile( qstring tsfilename, qstring langcode ) { qdomdocument tsfilexml; qfile xmlfile(tsfilename); if ( !xmlfile.open(qiodevice::readwrite) ) { qdebug() << "file not found." << endl; return filenotfound; } if ( !tsfilexml.setcontent(&xmlfile) ) { qdebug() << "invalid content in xml file : reading ts file. " << tsfilename << endl; xmlfile.close(); return invalidxmlfile; } qdomelement ts = tsfilexml.firstchildelement("ts"); if (ts.isnull()) { qdebug() << "invalid ts file" << endl; return invalidfile; } // in here, try change attribute. qdomattr attr = ts.attributenode("language"); attr.setvalue(langcode); ts.setattributenode(attr); xmlfile.close(); return readsuccess; }
the code runs perfectly, xml file not updated.
i tried following well.
ts.setattribute("language", langcode);
but no luck. don't know why not update xml file. please me.
i guess, think xml present in memory. have trigger somethink tsfilexml.writetofile(filename)
store changes file on filesystem.
Comments
Post a Comment