Пример #1
0
  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);
    }
  }
Пример #2
0
 // 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);
   }
 }
Пример #3
0
 public void endDocument() throws SAXException {
   nl();
   try {
     out.flush();
   } catch (IOException e) {
     throw new SAXException("I/O error", e);
   }
 }
Пример #4
0
 // ===========================================================
 // 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
   }
 }
Пример #5
0
 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
   }
 }
Пример #6
0
  // 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
    }
  }