PDA

View Full Version : QDom: Edit a child node?



nwarrenfl
8th May 2010, 22:34
Hi.

I am developing a class that handles xml configuration files.
Now i have a function that gets an existing node and edits it, however i can't find the correct solution to get it working.

Here is my code:

void XfireGamesList::updateConfiguredGame(QString pName, QString pLaunchExe, QString pDetectExe)
{
QDomElement game = getConfiguredGame(pName);
QDomElement command = game.firstChildElement("command");
QDomElement launch = command.firstChildElement("launch");

qDebug() << launch.text();
launch.setNodeValue("somevalue");
qDebug() << launch.text();
}

getConfiguredGame() returns a QDomElement representing this node for example:

<game name="The name of a certain game">
<command>
<launch>SOME_PATH</launch>
<detect>SOME_PATH</detect>
</command>
</game>

The function isn't able to edit the node values, and the debugging calls outputs "SOME_PATH" twice, so the node should be correct since it returns the correct values, but editing fails.

Does someone know why?
Thanks in advance.

Lykurg
8th May 2010, 22:43
You have to modify QDomText explicit.

nwarrenfl
8th May 2010, 22:51
You have to modify QDomText explicit.

I tried this:

launch.toText().setData("somevalue");

But this didn't work either, could you explain me the correct way?

Lykurg
9th May 2010, 10:28
Well, that could not work...
QString xml = "<game><command><launch>SOME_PATH</launch><detect>SOME_PATH</detect></command></game>";
QDomDocument doc;
doc.setContent(xml);
QDomElement game = doc.firstChildElement("game");
QDomElement command = game.firstChildElement("command");
QDomElement launch = command.firstChildElement("launch");
qWarning() << launch.text() << launch.childNodes().count();

QDomText text = doc.createTextNode("foo");
launch.replaceChild(text, launch.firstChild());
qWarning() << launch.text() << launch.childNodes().count(); Be aware that you check if the element has a text node!