Lab 7
Lab 7
Lab 7
University of Melbourne (Semester-2 2011) Department of Computer Science and Software Engineering
http://s620-37.csse.unimelb.edu.au:8080/Lab7/fetch.html 2. Explain in your report what is difference between SAX parser and DOM
parser?
Parsers are helper programs or libraries to do low level parsing in application from scratch. This low-level parsing ensure that document is well-formed and valid against its DTD or schema and also resolves character reference etc. Two common types of parser used are SAX and DOM and both work in different ways. DOM Parser i.e. Document Object Model Parser, loads the entire XML file into the primary memory before processing resulting in more memory occupation no matter how much is actually needed by the client. DOM represents document in a Tree structured manner thats why also called tree model parser. It can traverse in any direction and we can insert or delete nodes using DOM. Header files for DOM are 'javax.xml.parsers' and 'org.w3c.dom'. In comparison to this SAX i.e. Simple API for XML parses node by node and doesnt store the XML in memory and serves the client application always only with pieces of the document at any given time. Also traversing in SAX is always top to bottom with limitation of no insertion or deletion of nodes. SAX is an event based parser i.e. it works incrementally and generates events that are passed to the application, these event generations result in methods invocation called 'callback'. Header files for SAX includes 'javax.xml.parsers', 'org.xml.sax' and 'org.xml.sax.helpers'. SAX runs bit faster than DOM.