PDA

View Full Version : problem creating dom tree



dreamer
7th May 2008, 15:56
I have a problem when a try to create my dom tree.

In the constructor i build 2 objects:


QDomDocument *doc=new QDomDocument();
QDomElement root=doc->createElement("root");
doc->appendChild(root);


I'd like to fill the root node with some children and to have a structure like this:


<root>
<node1>
some text
</node1>
<node1>
sometext
</node2>
</root>


To obtain this behaviour i make:


QDomElement ele=doc->createElement("node1");
ele.appendChild(doc->createTextNode("some text");
root.appendChild(ele);


To find a node element i make:


root.elementsByTagName("node1");


To clean the dom tree, a make:


root.clear();


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

stevey
8th May 2008, 05:17
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?

dreamer
8th May 2008, 08:12
I resolve the problem, clearing my dom tree with the reallocation of a new QDomDocument instead of calling the function clear():



doc=new QDomDocument("doc");
root=doc->createElement("root");//root file
doc->appendChild(root);


And than, i use


doc->elementsByTagName("node1");


instead of :


root.elementsByTagName("node1");