Use of SAX Parsing in XML

In this article I am going to explain about parse XML document through SAX.
  • 2394

XML SAX Parsing

SAX Stands for Simple API for XML. It is main characteristic of XML that read each units of XML. SAX is an event based sequential access parser and developed by XML-DEV mailing list for XML document. SAX provide mechanisms for reading data from XML document. SAX parser operate each piece of XML document sequentially. SAX parser have some advantage over than DOM-style parser. SAX parser only need to reports each parsing as its happen. And discard almost all information after reports. In SAX parser minimum memory require for parsing is proportional to the maximum depth of the XML file and maximum data involve in single XML event.

  • SAX processes documents state-dependently.
  • A SAX parser only needs to report each parsing event as it happens.
  • The minimum memory required for a SAX parser is proportional to the maximum depth of the XML file.
  • SAX approach can cleverly cache information for later use.
  • SAX parsers operate on each piece of the XML document sequentially.

XML Parsing through SAX

When XML document pass through SAX parser following event will be generate.

  • Start XML element ( DocumentElement ) with an attribute.
  • Start XML element ( FirstElemeent ).
  • XML text node, some text.
  • End XML element ( FirstElement ).
  • Processing Instruction event,
  • Start XML element ( SecondElement ).
  • XML Text node, with data equal to "Pre-Text"
  • XML element start ( Inline )
  • XML Text node, with data equal to "Inlined text"
  • End XML element ( Inline ).
  • XML Text node, with data equal to "Post-text."
  • End XML element (SecondElement ).
  • End XML element ( DocumentElement ).


<?xml version="1.0" encoding="UTF-8"?>

<DocumentElement param="value">




  <?some_pi some_attr="somevalue"?>

  <SecondElement param2="value2">

    Pre-Text <Inline>Inlined text</Inline> Post-text.



Further Readings

You may also want to read these related articles: here
Ask Your Question 
Got a programming related question? You may want to post your question here


© 2020 DotNetHeaven. All rights reserved.