1 / 12

Java API for XML Processing

Java API for XML Processing. XML parsing model SAX. Contents. What is JAXP ? Uses for JAXP JAXP API Model & Implementations Processing XML with SAX. What is JAXP ?. Java API for XML Parsing JAXP 1.0 (1999) Supported SAX 1.0 and DOM Level 1 JAXP 1.1

hayley
Télécharger la présentation

Java API for XML Processing

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. Java API for XML Processing XML parsing model SAX

  2. Contents • What is JAXP ? • Uses for JAXP • JAXP API Model & Implementations • Processing XML with SAX

  3. What is JAXP ? • Java API for XML Parsing • JAXP 1.0 (1999) • Supported SAX 1.0 and DOM Level 1 • JAXP 1.1 • Supports SAX 2.0 & extension, DOM Level 2 • JAXP 1.3 ( included in J2SE 5.0 ) • Supports SAX 2.0.2, DOM Level 3 • Include Xerces ver 2.6.2+

  4. Uses for JAXP • Pluggability layer • Change parser without affecting the application logic • Standard interfaces that encapsulate the details behind parser interactions • choose a parser provider that best suits the requirements of the service

  5. JAXP API Model & Implementations • Parsing classes • Javax.xml.parsers package • Transformaction classes • Javax.xml.transform package • Many implementation • Sun Crimson(included JDK1.4) • ApacheXerces, IBM, Oracle

  6. Processing XML with SAX (1) • Event-driven processing model • Data elements are interpreted and callback • Biggest advantage • Not load XML documents ( fast, lightweight )

  7. Processing XML with SAX (2) • Steps • 1. Getting Factory and Parser class • 2. Setting options • Setting namespace, validation, features • 3. Implement DefaultHandler class • 4. Using SAX Parser

  8. Processing XML with SAX- Getting Factory and Parser class try { SAXParserFactory saxFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxFactory.newSAXParser(); } catch ( FactoryConfigurationError fce ) { // handle exception here } catch ( ParserConfigurationError pce ) { // handle exception here }

  9. Processing XML with SAX- Setting options Setting Namespace factory.setNameSpaceAware(boolean) boolean parser.isNamespaceAware() Setting Validation factory.setValidation(boolean) boolean parser.isValidating() Setting Features factory.setFeature(strName, boolean) boolean factory.getFeature(strName)

  10. Processing XML with SAX- Implement DefaultHandler class public class MySAXHandler extends DefaultHandler { public MySAXHandler() { } // overiding method public void startDocument() throws SAXException { } public void endDocument() throws SAXException { } public void characters(char[] buf, int offset, int len) throws SAXException { } public void startElement(String namespaceURI, String localName, String rowName, Attributes attrs ) throws SAXException { } public void endElement(String namespaceURI, String localName, String rowName) throws SAXException { }

  11. Processing XML with SAX- Using SAX Parser

  12. Sample SAX Parsing

More Related