/* * Xmltest.java * * Created on 6. květen 2002, 10:49 */ import org.xml.sax.*; import javax.xml.parsers.SAXParserFactory; /** * * @author pn97942 */ public class Xmltest { /** Creates a new instance of Xmltest */ public Xmltest() { } /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance (); factory.setValidating (false); factory.setNamespaceAware(false); Parser xp = factory.newSAXParser ().getParser (); Handler h = new Handler(); xp.setEntityResolver(h); xp.setDocumentHandler(h); xp.setErrorHandler(h); xp.parse("x.xml"); System.err.println("parsed"); } static class Handler extends HandlerBase { public void error(SAXParseException exception) throws SAXException { throw exception; } public void warning(SAXParseException exception) throws SAXException { throw exception; } public void fatalError(SAXParseException exception) throws SAXException { throw exception; } public void startElement(String name, AttributeList amap) throws SAXException { System.err.println("startElement(" + name + ")"); } public void endElement(String name) throws SAXException { System.err.println("endElement(" + name + ")"); } public void characters(char[] ch, int start, int length) throws SAXException { System.err.println("characters"); } public void startDocument() throws org.xml.sax.SAXException { System.err.println("startDocument"); } public void endDocument() throws org.xml.sax.SAXException { System.err.println("endDocument"); } public InputSource resolveEntity(java.lang.String pid,java.lang.String sid) throws SAXException { System.err.println("pid='" + pid + "', sid='" + sid + "'"); return new InputSource (sid); } } }