1

In this discussion about dom vs sax here

the chosen answer says:

DOM is easier to use but has an overhead of parsing the entire XML before you can start using it

I understood that in SAX, you dont need to parse the whole xml. Let us say that i am using Sax parser and i want to find a particular node. Now if the node is towards the end of the xml document, how will the sax parser find it without parsing the whole xml?

My other question is why in sax we cannot insert/delete a node? For some reason these answers are not obvious from the statement "sax is event based".

Community
  • 1
  • 1
Victor
  • 16,609
  • 71
  • 229
  • 409

1 Answers1

0

Both Dom and Sax method read the all file!

It just mean that Dom is parsing every node so that it create a tree in memory where you can get what you want using a Dom request.

Sax is different, it doesn't parse the file, it will just notify you with call back after each event that happen while reading it instead, like: startDocument, startElement, endElement, endDocument... in those method you can check the name of each tag/attribute for exemple and just pickup what you are interested in.

Gomino
  • 12,127
  • 4
  • 40
  • 49
  • thanks, but please elaborate. in your first line you say both methods read all the file but then you say sax doesnot parse the file. – Victor Aug 07 '13 at 14:30
  • I mean both methods load the file in memory and read it line by line, but SAX isn't doing any extra work, it just fire some events you can catch to actually store (parse) the data you want. While Dom is doing it for you and for all the document, then Dom provide you an easy access to each element of the file via DOM request – Gomino Aug 07 '13 at 14:41