xml8 - Simple API for XML (SAX) Outline Introduction...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Simple API for XML (SAX) Outline Introduction DOM vs. SAX SAX-based parsers Setup Events Example: Tree Diagram Case Study: Using SAX with the Day Planner Application SAX 2.0
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
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
Background image of page 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)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
SAX-based Parsers SAX-based parsers Available for variety of programming languages e.g., Java, Python, etc. We use Sun Microsystem’s JAXP
Background image of page 4
Some SAX-based parsers.   Product Description JAXP Sun’s JAXP is available from java.sun.com/xml . JAXP supports both SAX and DOM. Xerces Apache’s Xerces parser is available at www.apache.org . Xerces supports both SAX and DOM. MSXML 3.0 Microsoft’s msxml parser available at msdn.microsoft.com/xml . This parser supports both SAX and DOM.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
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
Background image of page 6
Events SAX parser Invokes certain methods when events occur Programmers override these methods to process data
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Methods invoked by the SAX parser Method Name Description setDocumentLocator Invoked at the beginning of parsing. startDocument Invoked when the parser encounters the start of an XML document. endDocument Invoked when the parser encounters the end of an XML document. startElement Invoked when the start tag of an element is encountered. endElement Invoked when the end tag of an element is encountered. characters Invoked when text characters are encountered. ignorableWhitespace Invoked when whitespace that can be safely ignored is encountered. processingInstruction Invoked when a processing instruction is encountered.
Background image of page 8
Example: Tree Diagram Java application Parse XML document with SAX-based parser Output document data as tree diagram extends org.xml.sax.HandlerBase implements interface EntityResolver Handles external entities implements interface DTDHandler Handles notations and unparsed entities implements interface DocumentHandler Handles parsing events implements interface ErrorHandler Handles errors
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline Fig. 9.3 Application  to create a tree  diagram for an XML  document.   import specifies location of classes needed by application Assists in formatting Override method to output parsed document’s URL 1 // Fig. 9.3 : Tree.java 2 // Using the SAX Parser to generate a tree diagram.
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/15/2011 for the course ECO 2023 taught by Professor Mr.raza during the Summer '10 term at FAU.

Page1 / 25

xml8 - Simple API for XML (SAX) Outline Introduction...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online