Results 1 to 3 of 3

Thread: problem creating dom tree

  1. #1
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question problem creating dom tree

    I have a problem when a try to create my dom tree.

    In the constructor i build 2 objects:
    Qt Code:
    1. QDomElement root=doc->createElement("root");
    2. doc->appendChild(root);
    To copy to clipboard, switch view to plain text mode 

    I'd like to fill the root node with some children and to have a structure like this:
    Qt Code:
    1. <root>
    2. <node1>
    3. some text
    4. </node1>
    5. <node1>
    6. sometext
    7. </node2>
    8. </root>
    To copy to clipboard, switch view to plain text mode 

    To obtain this behaviour i make:
    Qt Code:
    1. QDomElement ele=doc->createElement("node1");
    2. ele.appendChild(doc->createTextNode("some text");
    3. root.appendChild(ele);
    To copy to clipboard, switch view to plain text mode 

    To find a node element i make:
    Qt Code:
    1. root.elementsByTagName("node1");
    To copy to clipboard, switch view to plain text mode 

    To clean the dom tree, a make:
    Qt Code:
    1. root.clear();
    To copy to clipboard, switch view to plain text mode 

    What's wrang?? how can i obtain my behaviour???

  2. #2
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem creating dom tree

    Is this code even compiling? You're missing a closing bracket:
    ele.appendChild(doc->createTextNode("some text");
    If that's not the problem, then what's the result of your code?

  3. #3
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: problem creating dom tree

    I resolve the problem, clearing my dom tree with the reallocation of a new QDomDocument instead of calling the function clear():

    Qt Code:
    1. doc=new QDomDocument("doc");
    2. root=doc->createElement("root");//root file
    3. doc->appendChild(root);
    To copy to clipboard, switch view to plain text mode 

    And than, i use
    Qt Code:
    1. doc->elementsByTagName("node1");
    To copy to clipboard, switch view to plain text mode 

    instead of :
    Qt Code:
    1. root.elementsByTagName("node1");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. creating a Tree
    By mickey in forum General Programming
    Replies: 0
    Last Post: 20th April 2008, 17:57
  2. creating a tree hierarchy using QStandardModel
    By wind in forum Qt Programming
    Replies: 3
    Last Post: 19th September 2006, 21:54
  3. creating dll problem -> no exports ...
    By vrudolf in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2006, 16:47
  4. problem with tree view
    By boss_bhat in forum Newbie
    Replies: 4
    Last Post: 4th June 2006, 21:03
  5. Problem in creating thread in GUI application
    By jyoti kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:05

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.