Inserting node to Xml file
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.
Re: Inserting node to Xml file
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.
Code:
for(...)
{
button.setAttribute("tooltip", "...");
ui.appendChild(elem);
}
Re: Inserting node to Xml file
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 .