XML Tutorials - Herong's Tutorial Examples - v5.25, by Herong Yang
Using SAX Implementation in JDK
This section provides a tutorial example on how to use the SAX interface included in JDK 1.8, which actually uses SAX implementation provided by the org.apache.crimson package.
I have a simple program here, SAXClassChecker.java, to show what are the implementation classes provided JDK for the SAX interfaces:
/* SAXClassChecker.java * Copyright (c) 2002-2018 HerongYang.com. All Rights Reserved. */ import java.io.File; import java.io.IOException; import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParser; import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.SAXException; class SAXClassChecker { public static void main(String[] args) { try { File x = new File(args[0]); SAXParserFactory f = SAXParserFactory.newInstance(); System.out.println(f.toString()); SAXParser p = f.newSAXParser(); System.out.println(p.toString()); DefaultHandler h = new DefaultHandler(); System.out.println(h.toString()); p.parse(x,h); } catch (ParserConfigurationException e) { System.out.println(e.toString()); } catch (SAXException e) { System.out.println(e.toString()); } catch (IOException e) { System.out.println(e.toString()); } } }
If you compile and run this sample program in JDK (Java Development Kit), you will get:
herong> java SAXClassChecker hello.xml com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl@1db9742 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl@106d69c org.xml.sax.helpers.DefaultHandler@52e922
Note that:
Table of Contents
Introduction of XML (eXtensible Markup Language)
DOM (Document Object Model) Programming Interface
►SAX (Simple API for XML) Programming Interface
What Is SAX (Simple API for XML)
►Using SAX Implementation in JDK
SAXBrowser.java - SAX Interface Java Example
DTD (Document Type Definition) Introduction
Validating an XML Document against the Specified DTD Document Type
XSD (XML Schema Definition) Introduction
Validating XML Documents Against Specified XML Schemas
XSL (Extensible Stylesheet Language) Introduction
XSLT (XSL Transformations) Introduction
XSLT Elements as Programming Statements
Control and Generate XML Element in the Result
PHP Extensions for XML Manipulation
Processing XML with Python Scripts
XML Tools Plugin for Notepad++
XML Plugin Packages for Atom Editor