Package org.xml.sax

Examples of org.xml.sax.Parser


     * @exception Exception if any processing exception occurs
     */
    public void parse(URL url) throws Exception {

        // Construct a parser for our use
        Parser parser =
            ParserFactory.makeParser("org.apache.xerces.parsers.SAXParser");
        parser.setDocumentHandler(this);
        parser.setErrorHandler(this);

        // Perform the requested parse
        long before = System.currentTimeMillis();
        parser.parse(url.toString());
        long after = System.currentTimeMillis();

        // Log the results
        StaticLogger.write("Parsing time = " + (after - before) +
                           " milliseconds");
View Full Code Here


    {
        if (is == null) {
            throw new IllegalArgumentException("InputSource cannot be null");
        }
       
        Parser parser = this.getParser();
  if (hb != null) {
            parser.setDocumentHandler(hb);
            parser.setEntityResolver(hb);
            parser.setErrorHandler(hb);
            parser.setDTDHandler(hb);
  }
        parser.parse(is);
    }
View Full Code Here

    public static void print(String parserName, String uri, boolean validate) {

        try {
            SAXCount counter = new SAXCount();

            Parser parser = ParserFactory.makeParser(parserName);
            parser.setDocumentHandler(counter);
            parser.setErrorHandler(counter);
            try {
                //if (validate && parser instanceof XMLReader)
                if ( parser instanceof XMLReader ){
                    ((XMLReader)parser).setFeature( "http://xml.org/sax/features/validation",
                                                    validate);
                    ((XMLReader)parser).setFeature( "http://xml.org/sax/features/namespaces",
                                                    setNameSpaces );
                    ((XMLReader)parser).setFeature( "http://apache.org/xml/features/validation/schema",
                                                    setSchemaSupport );

                }
            } catch (Exception ex) {
            }

            if (warmup) {
                if (parser instanceof XMLReader)
                    ((XMLReader)parser).setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);

                parser.parse(uri);
                warmup = false;
            }
            long before = System.currentTimeMillis();
            parser.parse(uri);
            long after = System.currentTimeMillis();
            counter.printResults(uri, after - before);
        }
        catch (org.xml.sax.SAXParseException spe) {
            spe.printStackTrace(System.err);
View Full Code Here

            System.exit(1);
        }

        // create handler and setup parser
        HandlerBase handler = new DelayedInput();
        Parser parser = new SAXParser();
        parser.setDocumentHandler(handler);

        // read files
        for (int i = 0; i < argv.length; i++) {
            String arg = argv[i];
            System.out.println("argv["+i+"]: "+arg);
            InputStream stream = new DelayedInputStream(new FileInputStream(arg));
            InputSource source = new InputSource(stream);
            source.setSystemId(arg);
            parser.parse(source);
            stream.close();
        }

    } // main(String[])
View Full Code Here

    public static void print(String parserName, String uri, boolean canonical) {

        try {
            HandlerBase handler = new SAXWriter(canonical);

            Parser parser = ParserFactory.makeParser(parserName);
            parser.setDocumentHandler(handler);
            parser.setErrorHandler(handler);
            parser.parse(uri);
        }
        catch (Exception e) {
            e.printStackTrace(System.err);
        }
View Full Code Here

    public void parse(InputSource source, HandlerBase base)
    throws SAXException, IOException, IllegalArgumentException {
        if (source==null) throw new IllegalArgumentException();

        // Get the SAX parser instance
        Parser p=this.getParser();

        // Set the various handler instances
        if (base!=null) {
            p.setDocumentHandler(base);
            p.setDTDHandler(base);
            p.setEntityResolver(base);
            p.setErrorHandler(base);
        }

        // Parse the specified source
        p.parse(source);
    }
View Full Code Here

  if (bResolver != null) {
    spHandler.setEntityResolver(bResolver);
  }
  parser.parse(new InputSource(is), spHandler);
      } else {
  Parser parser = (Parser) Class.forName(parserClass).newInstance();
  parser.setDocumentHandler(this);
  if (bResolver != null) {
    parser.setEntityResolver(bResolver);
  }
  parser.parse(new InputSource(is));
      }
    } catch (ClassNotFoundException cnfe) {
      throw new CatalogException(CatalogException.UNPARSEABLE);
    } catch (IllegalAccessException iae) {
      throw new CatalogException(CatalogException.UNPARSEABLE);
View Full Code Here

    public static synchronized XMLReader createXMLReader ()
  throws SAXException
    {
  String className = System.getProperty("org.xml.sax.driver");
  if (className == null) {
      Parser parser;
      try {
    parser = ParserFactory.makeParser();
      } catch (Exception e) {
    parser = null;
      }
View Full Code Here

  if (bResolver != null) {
    spHandler.setEntityResolver(bResolver);
  }
  parser.parse(new InputSource(is), spHandler);
      } else {
  Parser parser = (Parser) Class.forName(parserClass).newInstance();
  parser.setDocumentHandler(this);
  if (bResolver != null) {
    parser.setEntityResolver(bResolver);
  }
  parser.parse(new InputSource(is));
      }
    } catch (ClassNotFoundException cnfe) {
      throw new CatalogException(CatalogException.UNPARSEABLE);
    } catch (IllegalAccessException iae) {
      throw new CatalogException(CatalogException.UNPARSEABLE);
View Full Code Here

        throws SAXException, IOException {
        if (is == null) {
            throw new IllegalArgumentException("InputSource cannot be null");
        }

        Parser parser = this.getParser();
        if (hb != null) {
            parser.setDocumentHandler(hb);
            parser.setEntityResolver(hb);
            parser.setErrorHandler(hb);
            parser.setDTDHandler(hb);
        }
        parser.parse(is);
    }
View Full Code Here

TOP

Related Classes of org.xml.sax.Parser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.