PDA

View Full Version : Inserting node to Xml file



vajindarladdad
13th April 2009, 09:26
Hello All Experts ,
I am developing an application in which i am using an Xml file to store some values.
I am using QDomDocument , and QDomElements .
I am able to create a single node like this

<ui name="UI EDITOR" >
<button tooltip="scFileOpen('/home/vajindar/Download/ex1.iges')" id="1" />
</ui>

But i want to create structure like this

<ui name="UI EDITOR" >
<button tooltip="scFileOpen('/home/vajindar/Download/ex1.iges')" id="1" />
<button tooltip="scFileOpen('/home/vajindar/Download/ex2.iges')" id="2" />
<button tooltip="scFileOpen('/home/vajindar/Download/ex3.iges')" id="3" />
<button tooltip="scFileOpen('/home/vajindar/Download/ex4.iges')" id="4" />
<button tooltip="scFileOpen('/home/vajindar/Download/ex5.iges')" id="5" />
</ui>

Can somebody provide me any helpful tips or example code to do the needful.

Lykurg
13th April 2009, 09:58
Show us your code for for creating a single "node" and we show you how to add more... Probably you only have to use appendChild multiple.


QDomElement ui = doc.createElement("ui");
for(...)
{
QDomElement button = doc.createElement("button");
button.setAttribute("tooltip", "...");
ui.appendChild(elem);
}

vajindarladdad
13th April 2009, 11:34
QDomDocument dom ;
QDomElement xui = dom.createElement("ui");
xui.setAttribute("name","UI EDITOR");
QDomElement xbutton = dom.createElement("button");
xbutton.setAttribute("tooltip",location);
xbutton.setAttribute("id",QString::number(id));

dom.appendChild(xui);
xui.appendChild(xbutton);

QFile file("xml/node.xml");
if(!file.open(QIODevice::ReadWrite | QIODevice::Text))
{
qDebug("Error... in opening a file");
return ;
}


QTextStream stream(&file);
stream<<dom.toString();
file.close();


Sir , This is a code to create a single node .