×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    XML - SAX or DOM

    I i'll need to read, and just read, a xml file in my aplication. The xml will describe something like 50 items, not a large file.
    In question of performance and memory what are the best? DOM or SAX for that case?

    Thanks

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: XML - SAX or DOM

    If you just need to read it, and not do anything with the data, then it doesn't matter.

    But I'm guessing you want to do something with the data, no? Not "just read" it?

    (And just to confuse the issue there's a third option known as "pull parsing"/)

  3. #3
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    Re: XML - SAX or DOM

    Quote Originally Posted by danhicksbyron View Post
    If you just need to read it, and not do anything with the data, then it doesn't matter.

    But I'm guessing you want to do something with the data, no? Not "just read" it?

    (And just to confuse the issue there's a third option known as "pull parsing"/)
    I want read the description and the link for each item. When i said that i just want to read i'm saying that i just want to read the xml and not write to the file because if i want to add itens i need to write.

    I did that post because i read somewhere that DOM is not good for large files because use a lot of memory.

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: XML - SAX or DOM

    The difference between SAX and DOM is that DOM reads the entire file into memory as C++ objects, while simply SAX parses the file and passes control to entry points in your code to deal with the individual entries. DOM is much easier to use in general, and a better choice if you need to "randomly" access the XML, or if you will need to access most of it over time. SAX requires more design/coding/care on your part, but is a good choice if you only need a few bits of the XML, or will extract the XML once, in a well-defined order.

    DOM, since it reads in the entire file and represents it as C++ objects, uses significant amounts of storage, roughly proportional to the file size. SAX, on the other hand, just needs storage for the few symbols it's parsing at the moment (though in your program you have to provide storage for the extracted data that you wish to retain). Also, SAX is genrally faster.

    But for a file of only 50 elements, it's unlikely that these size/speed issues would be very significant.

Similar Threads

  1. Replies: 12
    Last Post: 2010-03-21, 19:25
  2. XML DOM and server hickup issue
    By parsa28 in forum Mobile Java General
    Replies: 0
    Last Post: 2008-09-25, 20:28
  3. XML DOM parser in Symbian
    By prashs in forum Symbian
    Replies: 1
    Last Post: 2007-12-04, 17:25
  4. sax xml soumaya plz come in
    By isarc in forum Symbian
    Replies: 8
    Last Post: 2007-05-17, 08:09
  5. XML parser with SAX support
    By biju1176 in forum General Messaging
    Replies: 1
    Last Post: 2002-08-08, 10:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×