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