Package org.apache.xerces.parsers

Examples of org.apache.xerces.parsers.SAXParser


    catch(NoSuchMethodException e)
    {
      // Xerces version mismatch; neither Xerces1 nor Xerces2 succeeded.
      // Fall back on filtering solution.
      IncrementalSAXSource_Filter iss=new IncrementalSAXSource_Filter();
      iss.setXMLReader(new SAXParser());
      return iss;
    }
  }
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

       
        // construct handler
        DefaultHandler handler = new DocumentTracer();

        // construct parser; set features
        XMLReader parser = new SAXParser();
        try {
            parser.setFeature("http://xml.org/sax/features/namespaces", true);
        }
        catch (SAXException e) {
            e.printStackTrace(System.err);
        }
        try {
            parser.setFeature("http://xml.org/sax/features/validation", true);
        }
        catch (SAXException e) {
            e.printStackTrace(System.err);
        }

        // set handlers
        parser.setContentHandler(handler);
        parser.setDTDHandler(handler);
        parser.setErrorHandler(handler);
        try {
            parser.setProperty("http://xml.org/sax/properties/declaration-handler", handler);
        }
        catch (SAXException e) {
            e.printStackTrace(System.err);
        }
        try {
            parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
        }
        catch (SAXException e) {
            e.printStackTrace(System.err);
        }

        // parser files
        for (int i = 0; i < argv.length; i++) {
            String arg = argv[i];
            System.err.println("# argv["+i+"]: "+arg);
            //print(arg);
            try {
                parser.parse(arg);
            }
            catch (SAXException e) {
                Exception ex = e.getException();
                throw ex != null ? ex : e;
            }
View Full Code Here

         * Constructs a Client that connects to the given port in terse
         * output mode.
         */
        public Client(String address, int port) throws IOException {
            this(address, port, false);
            fParser = new SAXParser();
            fParser.setDocumentHandler(this);
            fParser.setErrorHandler(this);
        }
View Full Code Here

     * created and populated AppData structure
     */
    public AppData parseFile(String xmlFile, boolean skipValidation)
        throws Exception
    {
        SAXParser parser = new SAXParser();
       
        // set the Resolver for the database DTD
        DTDResolver dtdResolver = new DTDResolver();
        parser.setEntityResolver(dtdResolver);

        // We don't use an external content handler - we use this object
        parser.setContentHandler(this);
        parser.setErrorHandler(this);
       
        // Validate the input file
        parser.setFeature(
            "http://apache.org/xml/features/validation/dynamic", true);
        parser.setFeature("http://xml.org/sax/features/validation", true);

        FileReader fr = new FileReader (xmlFile);
        BufferedReader br = new BufferedReader (fr);
        try
        {
            InputSource is = new InputSource (br);
            parser.parse(is);
        }
        finally
        {
            br.close();
        }
View Full Code Here

     * Create a new <code>SAXParserFactoryImpl</code> instance.
     */
    protected SAXParserImpl(boolean namespaces, boolean validation)
    throws ParserConfigurationException {
        this();
        SAXParser p=new SAXParser();
        try {
            p.setFeature("http://xml.org/sax/features/namespaces",namespaces);
        } catch (SAXException e) {
            throw new ParserConfigurationException("Cannot set namespace "+
                "awareness to "+namespaces);
        }
        try {
            p.setFeature("http://xml.org/sax/features/validation",validation);
        } catch (SAXException e) {
            throw new ParserConfigurationException("Cannot set validation to "+
                validation);
        }
        this.namespaces=namespaces;
View Full Code Here

    /** the Entity Resolver */
    protected Resolver resolver = null;

    public XercesParser ()
    throws SAXException {
        this.parser = new SAXParser();

        this.parser.setFeature("http://xml.org/sax/features/validation",false);
        this.parser.setFeature("http://xml.org/sax/features/namespaces",true);
        this.parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
                          true);
View Full Code Here

        // it's not all that good to have a concrete dependency on Xerces
        // and a particular version, at that.
        // but schema support in the Xerces series of parsers is variable
        // and some of the configuration details differ.
        // At least this way seems reliable
        SAXParser parser = new SAXParser();
   
        // Set features
        parser.setFeature(NAMESPACES_FEATURE_ID, true);
        parser.setFeature(NAMESPACE_PREFIXES_FEATURE_ID, false);
        parser.setFeature(VALIDATION_FEATURE_ID, true);
        parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
        parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, false);
        parser.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, false);
   
        // Set properties
        parser.setProperty(NONAMESPACE_SCHEMA_LOCATION_PROPERTY_ID, "schema.xsd");
   
        XMLUnitHandler handler = new XMLUnitHandler(schemaSource);
   
        // Set handlers
        parser.setContentHandler(handler);
        parser.setErrorHandler(handler);
        parser.setEntityResolver(handler);
   
        // parse document
        parser.parse(documentSource);
        handler.reportErrors();
    }
View Full Code Here

    {
      // Fallback if this fails (implemented in createIncrementalSAXSource) is
      // to attempt Xerces-1 incremental setup. Can't do tail-call in
      // constructor, so create new, copy Xerces-1 initialization,
      // then throw it away... Ugh.
      IncrementalSAXSource_Xerces dummy=new IncrementalSAXSource_Xerces(new SAXParser());
      this.fParseSomeSetup=dummy.fParseSomeSetup;
      this.fParseSome=dummy.fParseSome;
      this.fIncrementalParser=dummy.fIncrementalParser;
    }
  }
View Full Code Here

    catch(NoSuchMethodException e)
    {
      // Xerces version mismatch; neither Xerces1 nor Xerces2 succeeded.
      // Fall back on filtering solution.
      IncrementalSAXSource_Filter iss=new IncrementalSAXSource_Filter();
      iss.setXMLReader(new SAXParser());
      return iss;
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.xerces.parsers.SAXParser

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.