XML SAX Parser Introduction

SAX Parser – Simple API for XML

SAX parser work differently with DOM parser.SAX parser is faster and uses less memory than DOM parser.SAX don’t load and XML document into memory and don’t create any object representation of XML document instead, SAX is use the event-driven model its provides callback method and the parser invokes them as it reads the XML data.                                            

Using SAX parser you can’t back up to an earlier part of document or rearrange it, any more than you can back up the serial data stream or rearrange characters you have read from than stream.                                 SAX will call listener object for following events:

  • startDocument
  • startElement
  • characters
  • comments
  • processing instructions
  • endElement
  • endDocument

SAX call back methods call the DefaultHandler (org.xml.sax.helpers.DefaultHandler).You should extend the Default handler override the following methods or use DefaultHandler as Inner Class.

Methods must be overridden are

startDocument() and endDocument() – methods called at start and end of an XML document
startElement() and endElement() – methods called at the start and end of each element.
characters() – method called when text contents between start and end of element

SAX is oriented towards state independent processing, where the handing of element does not depend on the previous elements.
See the SAX Parser example for more details Read XML File using Sax Parser

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. How to read XML file using SAX Parser
  2. XML SAX Parser Introduction
  3. How Read UTF-8 character XML file using SAX Parser
  4. Read XML File as List of Object using SAX Parser

Be the first to comment

Leave a Reply