PDA

View Full Version : QDom



mickey
13th September 2007, 01:20
Hi,
I have a look to QDomDocument, qDomElement and QDomNode and I don't understand good difference between Node and Element: both them have similar metodh (Am I understand wrong?): more Element inherit from Node: so it has couple of the same methods (or very similar). How does it implementation work? Wich is idea?

Thanks.

wysota
13th September 2007, 08:42
Not every node is an element but all elements are nodes. For instance there is a text node that represents plain text (contents of some other element). Take a look at what classes inherit QDomNode, that might give you a clue what a node is.

mickey
13th September 2007, 20:37
what I have understand is that a Node (that's a element) can have chils; eg: node1 has 4 childs that are: Node1_1 (node element), node1_2 (node text, that contains the text of node1), node1_3 (node attribute, that is attribute 1 of node1), node1_4 (node attribute, that is attribute 2 of node 1); then node1_1 can have childs......
1. Is it this?
2. WHat's the necessity of have the text in a Node? (the same quesition for the attribute, doesn't is enough a variabile text inside a NOde? (sure not beautiful....)

thanks

wysota
13th September 2007, 22:52
In the dom tree everything is a node, so text is a node as well. So if you have:


<xyz>abc</xyz>

then you have three nodes - the top level node holding the whole document, its child - the "xyz" element and the element's child - a text node holding "abc".

This way it is possible to easily manipulate the tree - adding, removing, modifying and moving nodes or subtrees. It wouldn't be that easy if text was a property of a node.

mickey
14th September 2007, 18:05
hi, what i don't have clear is:
whay a Node has method 2? I understand 1, but I'd put 2 in the QDomElement class. If element inherit from Node, what node know of the Element class?


//QdomNode class
1. QDomNode nextSibling () const
2. QDomElement nextSiblingElement ( const QString & tagName = QString() ) const

Furthermore I notice other things about this... why this?

wysota
15th September 2007, 11:26
Not every node is an element thus not every next sibling is an element node, thus the method. It's probably an equivalent to:

QDomNode n;
do {
n = nextSibling();
} while( !n.isElement());
return n;

Putting it into QDomElement would make it impossible to query for the next element from inside any node. The interface could probably be refactored, but this is really not Trolltech's concern. The DOM interface was developed by W3C, as far as I know.

mickey
16th September 2007, 14:47
Have QDom any function to select only a part of DomTree? (as Xpath)

wysota
16th September 2007, 14:55
No. There is XPath implementation for Qt available on Trolltech Labs (http://labs.trolltech.com).

mickey
17th September 2007, 15:56
No. There is XPath implementation for Qt available on Trolltech Labs (http://labs.trolltech.com).
Hi, I don't find it; anyway: how does xpath work? (does it use a particular "famous" algorith or on wich it bases on)

wysota
17th September 2007, 16:12
http://labs.trolltech.com/page/Projects/Internet/Patternist