public static void main(String[] args) { if (args.length <= 0) { System.out.println("Usage: java ExtractorDriver url"); return; } try { XMLReader parser = XMLReaderFactory.createXMLReader(); // Since this just writes onto the console, it's best // to use the system default encoding, which is what // we get by not specifying an explicit encoding here. Writer out = new OutputStreamWriter(System.out); ContentHandler handler = new TextExtractor(out); parser.setContentHandler(handler); // parser.parse("file:////c://myxml.xml"); parser.parse(args[0]); out.flush(); } catch (Exception e) { System.err.println(e); } }
// Wrap I/O exceptions in SAX exceptions, to // suit handler signature requirements private void emit(String s) throws SAXException { try { out.write(s); out.flush(); } catch (IOException e) { throw new SAXException("I/O error", e); } }
public void endDocument() throws SAXException { nl(); try { out.flush(); } catch (IOException e) { throw new SAXException("I/O error", e); } }
// =========================================================== // SAX DocumentHandler methods // =========================================================== public void setDocumentLocator(Locator l) { // Save this to resolve relative URIs or to give diagnostics. try { out.flush(); } catch (IOException e) { // Ignore errors } }
public void endDocument() throws SAXException { try { out.write(eol); out.flush(); out = null; } catch (IOException e) { throw new SAXException("I/O error", e); // NOT LOCALIZABLE } }
// helpers ... wrap I/O exceptions in SAX exceptions, to // suit handler signature requirements private void emit(String s) throws SAXException { try { if (s.equals("MULTIPLICITY")) { // NOT LOCALIZABLE int i = 0; } out.write(s); out.flush(); } catch (IOException e) { throw new SAXException("I/O error", e); // NOT LOCALIZABLE } }