View Poll Results: SAX2 or DOM?

Voters
7. You may not vote on this poll
  • I use SAX2 offcause

    3 42.86%
  • I use DOM offcause

    4 57.14%
Results 1 to 10 of 10

Thread: DOM or SAX2 xml handling?

  1. #1
    Join Date
    Aug 2006
    Posts
    25
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default DOM or SAX2 xml handling?

    I'm currious about which XML parser is used most.

    I my self have found the SAX2 easiest to use.

    But how about you? Which do you use and why?

  2. #2
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: DOM or SAX2 xml handling?

    This question does not make any sense. There are problems, which are easier solved with SAX2, others with DOM. DOM and SAX2 are tools, good developers know both and know when to choose which.

  3. #3
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: DOM or SAX2 xml handling?

    You use the different parsers depending on your needs. DOM parses the XML and creates a complete tree for you. It's easy to use, but takes up a lot of memory. SAX parses the XML token by token and calls the handlers you've written to deal with them. It's more work up front to use, but doesn't consume much memory.

  4. #4
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DOM or SAX2 xml handling?


  5. #5
    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: DOM or SAX2 xml handling?

    AFAIK it is to make SAX obsolete - the idea is simmilar, it's just easier to handle. Personally I use DOM. I think I might do differently for handling really large xml files, but as I don't have to deal with such files, I don't have to deal will a sequential approach.

  6. #6
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: DOM or SAX2 xml handling?

    Quote Originally Posted by wysota View Post
    I think I might do differently for handling really large xml files, but as I don't have to deal with such files, I don't have to deal will a sequential approach.
    SAX2 is not necessarily about large files. For instance it can be easily utilized to create print layouts. You have your handles, which draw circles, lines, text, etc and the SAX parser calls them sequentially with parameters from the controlling XML file. This way you 'draw' to a QPrinter.

    In this scenario you are not interested a particular data structure in memory. Choosing DOM would be definitely the wrong tool.

    I don't really see SAX2 and DOM as interchangeably. When your problem actually demands a DOM approach, but because of memory problems you are forced to use SAX2, it always is an ugly crutch.

    I'd say: Use SAX2 if you have to control something, use DOM if you have to store something. Of course this is only a rough guideline.

  7. #7
    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: DOM or SAX2 xml handling?

    Quote Originally Posted by Kumosan View Post
    I'd say: Use SAX2 if you have to control something, use DOM if you have to store something. Of course this is only a rough guideline.
    If the xml stores a sequence then I agree that using SAX is easy with it, but I wouldn't say you shouldn't use DOM. Depends how you want to handle the data - if it has some kind of hierarchy which you want to process in a non-sequence manner, it's easier to use DOM.

    And the obvious benefit of using DOM is that you don't have to implement any handlers

  8. #8
    Join Date
    Aug 2006
    Posts
    25
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DOM or SAX2 xml handling?

    Quote Originally Posted by wysota View Post
    If the xml stores a sequence then I agree that using SAX is easy with it, but I wouldn't say you shouldn't use DOM. Depends how you want to handle the data - if it has some kind of hierarchy which you want to process in a non-sequence manner, it's easier to use DOM.

    And the obvious benefit of using DOM is that you don't have to implement any handlers
    Exactly the lack of handlers in DOM made it difficult for me to understand.
    And its tree structure thingy.
    I can only atm see one application for that; for parsing configuration files which
    are somewhat static in layout.
    (I still haven't figured out how to use DOM though)

    the SAX on the other hand made just enough sense that it was easy to implement as
    a handler to server generated responses.
    Where some tags meight popup and meight never, and where the general structure
    could change from call to call.

    thanks for all the feedback and oppinions,

    (and on a side note could all please disregard the word offcause in the selection choises )

  9. #9
    Join Date
    Mar 2007
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DOM or SAX2 xml handling?

    The only app I've written that uses XML used DOM, mostly because I hate writing handlers. DOM is actually pretty useful for anything with a tree structure. You can easily pass subtrees around to different functions. For example, with this XML fragment:
    Qt Code:
    1. <scene>
    2. <models>
    3. <model/>
    4. <model/>
    5. </models>
    6. <textures>
    7. <texture/>
    8. <texture/>
    9. </textures>
    10. </scene>
    To copy to clipboard, switch view to plain text mode 
    DOM is great. You have a readTextureInfo() function, and you can pass it the node corresponding to the <textures> element. It can then handle the textures as it sees fit. (I'm actually using this style in an app I wrote I while back, though it's not Qt based.)

    I would probably use SAX for a configuration file, or something else that's kind of flat-ish.

  10. #10
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: DOM or SAX2 xml handling?

    I'm using DOM where hierarchy is known and SAX2 otherwise i.e. most of time i'm using SAX2

Similar Threads

  1. Exception handling in Qt 4.2.2
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2007, 09:47
  2. QGraphicsTextItem: handling cursor position change
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2007, 10:42
  3. need help for tree Handling concept
    By jyoti in forum Qt Programming
    Replies: 5
    Last Post: 24th November 2006, 04:52
  4. Keyboard Handling
    By ToddAtWSU in forum Qt Programming
    Replies: 4
    Last Post: 5th July 2006, 13:25
  5. Handling multiple UDP sockets
    By ecphora in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:01

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.