Results 1 to 3 of 3

Thread: Inserting node to Xml file

  1. #1
    Join Date
    Dec 2008
    Location
    PUNE (INDIA)
    Posts
    49
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.
    Thanks & Regards ,

    Vajindar Laddad .
    Trainee Developer.
    (INDIA).
    91+9325014248

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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.
    Qt Code:
    1. QDomElement ui = doc.createElement("ui");
    2. for(...)
    3. {
    4. QDomElement button = doc.createElement("button");
    5. button.setAttribute("tooltip", "...");
    6. ui.appendChild(elem);
    7. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2008
    Location
    PUNE (INDIA)
    Posts
    49
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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 .
    Thanks & Regards ,

    Vajindar Laddad .
    Trainee Developer.
    (INDIA).
    91+9325014248

Similar Threads

  1. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  2. Can you specify a file engine?
    By skimber in forum Qt Programming
    Replies: 2
    Last Post: 18th September 2008, 15:54
  3. remove node in xml file
    By mattia in forum Newbie
    Replies: 1
    Last Post: 6th March 2008, 13:25
  4. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.