Results 1 to 10 of 10

Thread: QDom

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default QDom

    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.
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDom

    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.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: QDom

    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
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDom

    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.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: QDom

    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?
    Qt Code:
    1. //QdomNode class
    2. 1. QDomNode nextSibling () const
    3. 2. QDomElement nextSiblingElement ( const QString & tagName = QString() ) const
    To copy to clipboard, switch view to plain text mode 
    Furthermore I notice other things about this... why this?
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDom

    Not every node is an element thus not every next sibling is an element node, thus the method. It's probably an equivalent to:
    Qt Code:
    1. do {
    2. n = nextSibling();
    3. } while( !n.isElement());
    4. return n;
    To copy to clipboard, switch view to plain text mode 

    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.

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: QDom

    Have QDom any function to select only a part of DomTree? (as Xpath)

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDom

    No. There is XPath implementation for Qt available on Trolltech Labs.

  9. #9
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: QDom

    Quote Originally Posted by wysota View Post
    No. There is XPath implementation for Qt available on Trolltech Labs.
    Hi, I don't find it; anyway: how does xpath work? (does it use a particular "famous" algorith or on wich it bases on)
    Regards

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

Similar Threads

  1. 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.