Results 1 to 5 of 5

Thread: The difference beteen QDomNode and QDomElement

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    369
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default The difference beteen QDomNode and QDomElement

    I am writing an applications which uses a lot of XML for it's input. Until now I have been using QDomNode, and now I saw that there is a QDomElement class which can be used as well. I see that QDomElement is more suitable for me, since I can query it's sub childs
    Qt Code:
    1. QDomElement::elementsByTagName()
    To copy to clipboard, switch view to plain text mode 
    but this still returns to me a QDomNode list, which in turn can be converted to elements.

    My question is why there is this separation between elements and nodes? Is it really needed? This just makes my code lines way larger....

    edit:
    Lets give you an example of those monstrosities:
    Qt Code:
    1. e.start = node.toElement().elementsByTagName("start-regex").item(0).toElement().text();
    To copy to clipboard, switch view to plain text mode 
    Last edited by elcuco; 6th January 2006 at 10:47.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The difference beteen QDomNode and QDomElement

    Quote Originally Posted by elcuco
    My question is why there is this separation between elements and nodes?
    Because not every node is an element. Of course it would be simplier if would QDomElement::elementsByTagName() return list of elements, but this method was defined in DOM specification like this:
    IDL Code:
    1. interface Element : Node {
    2. ...
    3. NodeList getElementsByTagName(in DOMString name);
    4. ...
    5. };
    To copy to clipboard, switch view to plain text mode 
    So the Trolls had not much choice.

  3. #3
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The difference beteen QDomNode and QDomElement

    As the name suggests QDomNode gives you a node in the tree structure.
    QDomNode will give u a particular node, its siblings, no of children etc....

    QDomElement on the other hand does not have information about the neighbors. It knows only about the given node, its attributes, tags and the text.

    Hope i have cleared your doubt.

    Cheers

  4. #4
    Join Date
    Jan 2006
    Posts
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: The difference beteen QDomNode and QDomElement

    The difference is that node can also be a comment, or a processing instruction, or text data.
    So be careful when iterating over the result and calling toElement, it could fail on e.g. comments.

    See the section QDomElement at the bottom of
    http://developer.kde.org/documentati.../mistakes.html

    PS: previous reply is wrong; an element does know about its siblings since an element *is* a node.

  5. #5
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The difference beteen QDomNode and QDomElement

    Ya, my mistake.

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.