Package org.apache.xerces.parsers

Examples of org.apache.xerces.parsers.SAXParser


                    parser = XMLReaderFactory.createXMLReader();
                }
                // If something went wrong with the factory
                // just use our own SAX parser.
                catch (SAXException se) {
                    parser = new SAXParser();
                }
                try {
                    parser.setFeature(NAMESPACE_PREFIXES, true);
                    namespacePrefixes = true;
                }
View Full Code Here


                    parser = XMLReaderFactory.createXMLReader();
                }
                // If something went wrong with the factory
                // just use our own SAX parser.
                catch (SAXException se) {
                    parser = new SAXParser();
                }
                try {
                    parser.setFeature(NAMESPACE_PREFIXES, true);
                    namespacePrefixes = true;
                }
View Full Code Here

    }

    // private methods
    private synchronized void writeToSAX(ContentHandler handler) {
        // nothing must go wrong with this parse...
        SAXParser parser = fGrammar.getSAXParser();
        StringReader aReader = new StringReader(fData);
        InputSource aSource = new InputSource(aReader);
        parser.setContentHandler(handler);
        try {
            parser.parse(aSource);
        } catch (SAXException e) {
            // this should never happen!
            // REVISIT:  what to do with this?; should really not
            // eat it...
        } catch (IOException i) {
View Full Code Here

        return parser;
    }

    synchronized SAXParser getSAXParser() {
        if (fSAXParser != null) {
            SAXParser parser = (SAXParser) fSAXParser.get();
            if (parser != null) {
                return parser;
            }
        }
        // REVISIT:  when schema handles XML 1.1, will need to
        // revisit this (and the practice of not prepending an XML decl to the annotation string
        XML11Configuration config = new XML11Configuration(fSymbolTable);
        // note that this should never produce errors or require
        // entity resolution, so just a barebones configuration with
        // a couple of feature  set will do fine
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
        SAXParser parser = new SAXParser(config);
        fSAXParser = new SoftReference(parser);
        return parser;
    }
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

        String schemaFile = resource.getFile();
        GDataAccount account = null;
        /*
         * Force using apache xerces parser for digester
         */
        SAXParser parser = new SAXParser();
        parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
        parser.setFeature("http://apache.org/xml/features/validation/schema",true);
        parser.setFeature("http://xml.org/sax/features/validation",true);
        parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schemaFile);
        Digester digester = new Digester(parser);
        digester.setValidating(true);
        digester.setErrorHandler(new SimpleSaxErrorHandler());
        digester.setSchema(schemaFile);
        digester.addObjectCreate("account", GDataAccount.class);
View Full Code Here

    static void buildRegistry() throws IOException, SAXException {
        String schemaFile = RegistryBuilder.class.getResource("/gdata-config.xsd").getFile();
        /*
         * Force using apache xerces parser for digester
         */
        SAXParser parser = new SAXParser();
        parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
        parser.setFeature("http://apache.org/xml/features/validation/schema",true);
        parser.setFeature("http://xml.org/sax/features/validation",true);
        parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schemaFile);
        Digester digester = new Digester(parser);
        buildFromConfiguration(digester, GDataServerRegistry
                .getRegistry(),schemaFile);

    }
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

        return parser;
    }

    synchronized SAXParser getSAXParser() {
        if (fSAXParser != null) {
            SAXParser parser = (SAXParser) fSAXParser.get();
            if (parser != null) {
                return parser;
            }
        }
        // REVISIT:  when schema handles XML 1.1, will need to
        // revisit this (and the practice of not prepending an XML decl to the annotation string
        XML11Configuration config = new XML11Configuration(fSymbolTable);
        // note that this should never produce errors or require
        // entity resolution, so just a barebones configuration with
        // a couple of feature  set will do fine
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
        SAXParser parser = new SAXParser(config);
        fSAXParser = new SoftReference(parser);
        return parser;
    }
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);
    }
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.