Results 1 to 4 of 4

Thread: QDom: Edit a child node?

  1. #1
    Join Date
    May 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QDom: Edit a child node?

    Hi.

    I am developing a class that handles xml configuration files.
    Now i have a function that gets an existing node and edits it, however i can't find the correct solution to get it working.

    Here is my code:
    Qt Code:
    1. void XfireGamesList::updateConfiguredGame(QString pName, QString pLaunchExe, QString pDetectExe)
    2. {
    3. QDomElement game = getConfiguredGame(pName);
    4. QDomElement command = game.firstChildElement("command");
    5. QDomElement launch = command.firstChildElement("launch");
    6.  
    7. qDebug() << launch.text();
    8. launch.setNodeValue("somevalue");
    9. qDebug() << launch.text();
    10. }
    To copy to clipboard, switch view to plain text mode 

    getConfiguredGame() returns a QDomElement representing this node for example:
    Qt Code:
    1. <game name="The name of a certain game">
    2. <command>
    3. <launch>SOME_PATH</launch>
    4. <detect>SOME_PATH</detect>
    5. </command>
    6. </game>
    To copy to clipboard, switch view to plain text mode 

    The function isn't able to edit the node values, and the debugging calls outputs "SOME_PATH" twice, so the node should be correct since it returns the correct values, but editing fails.

    Does someone know why?
    Thanks in advance.

  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: QDom: Edit a child node?

    You have to modify QDomText explicit.

  3. #3
    Join Date
    May 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QDom: Edit a child node?

    Quote Originally Posted by Lykurg View Post
    You have to modify QDomText explicit.
    I tried this:
    Qt Code:
    1. launch.toText().setData("somevalue");
    To copy to clipboard, switch view to plain text mode 

    But this didn't work either, could you explain me the correct way?

  4. #4
    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: QDom: Edit a child node?

    Well, that could not work...
    Qt Code:
    1. QString xml = "<game><command><launch>SOME_PATH</launch><detect>SOME_PATH</detect></command></game>";
    2. doc.setContent(xml);
    3. QDomElement game = doc.firstChildElement("game");
    4. QDomElement command = game.firstChildElement("command");
    5. QDomElement launch = command.firstChildElement("launch");
    6. qWarning() << launch.text() << launch.childNodes().count();
    7.  
    8. QDomText text = doc.createTextNode("foo");
    9. launch.replaceChild(text, launch.firstChild());
    10. qWarning() << launch.text() << launch.childNodes().count();
    To copy to clipboard, switch view to plain text mode 
    Be aware that you check if the element has a text node!

Similar Threads

  1. QDom & xhtml
    By Potch in forum Newbie
    Replies: 3
    Last Post: 19th February 2010, 23:41
  2. how to justfy a node is leaf node or not
    By weixj2003ld in forum Qt Programming
    Replies: 4
    Last Post: 9th April 2009, 07:40
  3. XML editing with QDom
    By trulysachin in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2008, 16:39
  4. QDom
    By mickey in forum General Programming
    Replies: 9
    Last Post: 17th September 2007, 16:12
  5. parsing using QDOM
    By aruna in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2007, 12:46

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.