void Ribbon
::WriteXml(int id ,
QString location
) {
QFile file("xml/node.xml");
if(id==1) //creating ui , ribbon , tab , pabel , button node for the first time
{
QDomElement uiElementNode , documentElement , ribbonElementNode , tabElementNode , panelElementNode , buttonElementNode;
{
qDebug("Error... in opening a file");
return ;
}
uiElementNode = document.createElement("ui");
uiElementNode.setAttribute("name", "UI EDITOR");
document.appendChild(uiElementNode);
ribbonElementNode = document.createElement("ribbon");
uiElementNode.appendChild(ribbonElementNode);
tabElementNode = document.createElement("tab");
ribbonElementNode.appendChild(tabElementNode);
panelElementNode = document.createElement("panel");
tabElementNode.appendChild(panelElementNode);
buttonElementNode = document.createElement("button");
panelElementNode.appendChild(buttonElementNode);
}
else // here we need to insert button node to the panel
{
{
QMessageBox::warning(this, tr
("Error"),
"Error... in opening a file");
return ;
}
if( !document.setContent( &file ) )
{
QMessageBox::warning(this, tr
("Error"),
"Failed to parse the file into a DOM tree.");
return ;
}
QDomElement documentElement
= document.
documentElement();
//returns the root element QDomNodeList elements
= documentElement.
elementsByTagName( "panel" );
//searching for the panel node QDomElement newButton
= document.
createElement("button");
//creating new button panel.appendChild(newButton); //appending to the panel node
}
out << document.toString(); //writting to a file
file.close();
}
void Ribbon::WriteXml(int id ,QString location)
{
QFile file("xml/node.xml");
QDomDocument document ;
if(id==1) //creating ui , ribbon , tab , pabel , button node for the first time
{
QDomElement uiElementNode , documentElement , ribbonElementNode , tabElementNode , panelElementNode , buttonElementNode;
if(!file.open(QIODevice::ReadWrite | QIODevice::Text))
{
qDebug("Error... in opening a file");
return ;
}
uiElementNode = document.createElement("ui");
uiElementNode.setAttribute("name", "UI EDITOR");
document.appendChild(uiElementNode);
ribbonElementNode = document.createElement("ribbon");
uiElementNode.appendChild(ribbonElementNode);
tabElementNode = document.createElement("tab");
ribbonElementNode.appendChild(tabElementNode);
panelElementNode = document.createElement("panel");
tabElementNode.appendChild(panelElementNode);
buttonElementNode = document.createElement("button");
panelElementNode.appendChild(buttonElementNode);
}
else // here we need to insert button node to the panel
{
if(!file.open(QIODevice::ReadWrite | QIODevice::Text))
{
QMessageBox::warning(this, tr("Error"), "Error... in opening a file");
return ;
}
if( !document.setContent( &file ) )
{
QMessageBox::warning(this, tr("Error"), "Failed to parse the file into a DOM tree.");
return ;
}
QDomElement documentElement = document.documentElement(); //returns the root element
QDomNodeList elements = documentElement.elementsByTagName( "panel" ); //searching for the panel node
QDomElement panel = elements.at(0).toElement();
QDomElement newButton = document.createElement("button");//creating new button
panel.appendChild(newButton); //appending to the panel node
}
QTextStream out(&file);
out << document.toString(); //writting to a file
file.close();
}
To copy to clipboard, switch view to plain text mode
Hello All experts this is my code to create the xml file.
I want result in following format
<ui name="UI EDITOR" >
<ribbon>
<tab/>
<panel>
<button/>
<button/>
</panel>
</ribbon>
</ui>
<ui name="UI EDITOR" >
<ribbon>
<tab/>
<panel>
<button/>
<button/>
</panel>
</ribbon>
</ui>
To copy to clipboard, switch view to plain text mode
But i am getting result in this format
<ui name="UI EDITOR" >
<ribbon>
<tab/>
<panel>
<button/>
</panel>
</ribbon>
</ui>
<ui name="UI EDITOR" >
<ribbon>
<tab/>
<panel>
<button/>
<button/>
</panel>
</ribbon>
</ui>
<ui name="UI EDITOR" >
<ribbon>
<tab/>
<panel>
<button/>
</panel>
</ribbon>
</ui>
<ui name="UI EDITOR" >
<ribbon>
<tab/>
<panel>
<button/>
<button/>
</panel>
</ribbon>
</ui>
To copy to clipboard, switch view to plain text mode
Please tell me where i am commiting mistake
I WANT TO INSERT THE button NODE DYNAMICALLY
Bookmarks