We are moved to new domain
Click -> www.ehowtonow.com
Sunday, 10 November 2013

SAX Parser Introduction


SAX – 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

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

See the SAX Parser example for more details Read XML File using Sax Parser

SAX is oriented towards state independent processing, where the handing of element does not depend  on the previous elements.

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: SAX Parser Introduction Rating: 5 Reviewed By: eHowToNow