1 / 10

Simple API for XML (SAX)

Simple API for XML (SAX). Outline 1 Introduction 2 DOM vs. SAX 3 SAX-based parsers 4 Setup 5 Events 6 SAX 2.0. 1 Introduction. SAX Simple API for XML Another method for accessing XML document’s contents Developed by XML-DEV mailing-list members Uses event-based model

jamil
Download Presentation

Simple API for XML (SAX)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Simple API for XML (SAX) Outline1 Introduction2 DOM vs. SAX3 SAX-based parsers4 Setup5 Events6 SAX 2.0

  2. 1 Introduction • SAX • Simple API for XML • Another method for accessing XML document’s contents • Developed by XML-DEV mailing-list members • Uses event-based model • Notifications (events) are raised as document is parsed

  3. 2 DOM vs. SAX • DOM • Tree-based model • Stores document data in node hierarcy • Data is accessed quickly • Provides facilities for adding and removing nodes • SAX • Invoke methods when markup (specific tag) is encountered • Greater performance than DOM • Less memory overhead than DOM • Typically used for reading documents (not modifying them)

  4. 3 SAX-based Parsers • SAX-based parsers • Available for variety of programming languages • e.g., Java, Python, etc. • Sun Microsystem’s JAXP

  5. Fig. 1 Some SAX-based parsers.

  6. 4 Setup • Java applications to illustrate SAX API • Java 2 Standard Edition required • Download at www.java.sun.com/j2se • Installation instructions • www.deitel.com/faq/java3install.htm • JAXP required • Download at java.sun.com/xml/download.html

  7. 5 Events • SAX parser • Invokes certain methods (Fig. 2) when events occur • Programmers override these methods to process data

  8. Fig. 2 Methods invoked by the SAX parser

  9. 6 SAX 2.0 • SAX 2.0 • Recently released • We have been using JAXP • JAXP supports only SAX 1.0 (currently) • Xerces parser (Apache) supports SAX 2.0

  10. 6 SAX 2.0 (cont.) • SAX 2.0 major changes • Class HandlerBase replaced with DefaultHandler • Element and attribute processing support namespaces • Loading and parsing processes has changed • Methods for retrieving and setting parser properties • e.g., whether parser performs validation

More Related