Hi
How to update a textnode data in xml through QDomElement.
I have following code
root = doc.createElement("root");
if(!file->exists())
{
id_text = doc.createTextNode("0");
root.appendChild(id);
id.appendChild(id_text);
doc.appendChild(root);
}
else
{
file
->open
(QFile::ReadWrite);
doc.setContent(file);
root1 = doc.documentElement();
int a = string_data.toInt();
qDebug()<<string_data;
string_data.clear();
id_text = doc.createTextNode("Qt"); // Here i want to write Qt but it is getting write 0Qt on the textnode.
node.appendChild(id_text);
statement = doc.createElement("statement");
condition_node = doc.createElement("condition");
action_node = doc.createElement("action");
QDomText condition_text
= doc.
createTextNode(condition_text_edit
->toPlainText
());
QDomText action_text
= doc.
createTextNode(action_text_edit
->toPlainText
());
statement.setAttribute("id", i);
statement.appendChild(condition_node);
statement.appendChild(action_node);
condition_node.appendChild(condition_text);
action_node.appendChild(action_text);
root1.appendChild(statement);
// QString str = statement.attribute("id");
// qDebug()<<str.toInt();
file->seek(0);
}
doc.save(out, Indent);
static QDomDocument doc;
static QDomElement root,root1;
QDomElement statement, action_node, condition_node;
QDomText id_text;
root = doc.createElement("root");
QFile *file = new QFile("E:/new.txt");
if(!file->exists())
{
file->open(QIODevice::WriteOnly);
QDomElement id = doc.createElement("id");
id_text = doc.createTextNode("0");
root.appendChild(id);
id.appendChild(id_text);
doc.appendChild(root);
}
else
{
file->open(QFile::ReadWrite);
doc.setContent(file);
root1 = doc.documentElement();
QDomElement node = root1.firstChildElement("id");
QString string_data = node.text();
int a = string_data.toInt();
qDebug()<<string_data;
string_data.clear();
id_text = doc.createTextNode("Qt"); // Here i want to write Qt but it is getting write 0Qt on the textnode.
node.appendChild(id_text);
statement = doc.createElement("statement");
condition_node = doc.createElement("condition");
action_node = doc.createElement("action");
QDomText condition_text = doc.createTextNode(condition_text_edit->toPlainText());
QDomText action_text = doc.createTextNode(action_text_edit->toPlainText());
statement.setAttribute("id", i);
statement.appendChild(condition_node);
statement.appendChild(action_node);
condition_node.appendChild(condition_text);
action_node.appendChild(action_text);
root1.appendChild(statement);
// QString str = statement.attribute("id");
// qDebug()<<str.toInt();
file->seek(0);
}
QTextStream out(file);
doc.save(out, Indent);
To copy to clipboard, switch view to plain text mode
So i want to update the textnode value while it is getting append in previous value.
Please anyone help me.
Waiting for response.
Bookmarks