Introduction to SAX Parsers |
|
A DOM parser reads an entire XML document and creates a DOM tree. If you do not need to process the document at runtime, a DOM parser can consume excess computer resources. In addition, if only a small portion of the document needs to be processed, reading the entire document takes more memory space. In such cases, a SAX parser helps provide efficient performance because the parsers do not need to maintain an internal tree structure representation of the XML document. SAX parsers are event-based, which means parsers generate specific events each time for every XML syntax. Applications can process these events to generate required information. Depending on the requirements, applications can customize SAX parsers to call specific methods to process XML documents. These methods are defined as callback methods in the ContentHandler interface, which is defined in the SAX API. For example, the startElement method is called when the parser comes to a less than symbol (<). Another method is the characters method, which is called when the parser reads character data. |
![]() |
Click the Next button to continue. |