100 likes | 288 Views
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
E N D
Simple API for XML (SAX) Outline1 Introduction2 DOM vs. SAX3 SAX-based parsers4 Setup5 Events6 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 • Notifications (events) are raised as document is parsed
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)
3 SAX-based Parsers • SAX-based parsers • Available for variety of programming languages • e.g., Java, Python, etc. • Sun Microsystem’s JAXP
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
5 Events • SAX parser • Invokes certain methods (Fig. 2) when events occur • Programmers override these methods to process data
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
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