Java tutorial
//package com.java2s; import org.xml.sax.*; import org.xml.sax.helpers.DefaultHandler; import java.io.*; import javax.xml.parsers.*; public class Main { /** The factory from whence we obtain XMLReader objects */ protected static SAXParserFactory _pfactory; /** * Parse the XML data in the given input stream, using the * specified handler object as both the content and error handler. * * @param handler the SAX event handler * @param in the input stream containing the XML to be parsed */ public static void parse(DefaultHandler handler, InputStream in) throws IOException, ParserConfigurationException, SAXException { XMLReader xr = _pfactory.newSAXParser().getXMLReader(); xr.setContentHandler(handler); xr.setErrorHandler(handler); xr.parse(new InputSource(in)); } }