Java XML SAX Parser getSchema(File xsd, ErrorHandler errorHandler)

Here you can find the source of getSchema(File xsd, ErrorHandler errorHandler)

Description

Gets the schema.

License

Apache License

Parameter

Parameter Description
xsd the xsd
errorHandler the error handler

Exception

Parameter Description
SAXException the sAX exception

Return

the schema

Declaration

public static Schema getSchema(File xsd, ErrorHandler errorHandler) throws SAXException 

Method Source Code

//package com.java2s;
/**/*from   www .  j av  a  2  s  . com*/
 * Copyright (C) 2007 Asterios Raptis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;

import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;

public class Main {
    /** The Constant HTTP_WWW_W3_ORG_2001_XML_SCHEMA. */
    private static final String HTTP_WWW_W3_ORG_2001_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";

    /**
     * Gets the schema.
     *
     * @param xsd
     *            the xsd
     * @param errorHandler
     *            the error handler
     * @return the schema
     * @throws SAXException
     *             the sAX exception
     */
    public static Schema getSchema(File xsd, ErrorHandler errorHandler) throws SAXException {
        // Create a new instance for an XSD-aware SchemaFactory
        SchemaFactory schemaFactory = SchemaFactory.newInstance(HTTP_WWW_W3_ORG_2001_XML_SCHEMA);

        // Set the ErrorHandler implementation.
        schemaFactory.setErrorHandler(errorHandler);

        // get the custom xsd schema that describes
        // the required format for my XML files.
        return schemaFactory.newSchema(xsd);
    }
}

Related

  1. getSAXParser()
  2. getSAXParser()
  3. getSAXParser()
  4. getSAXParserFactory()
  5. getSAXSDDriver()
  6. getSchema(URL xml_schema)
  7. getSchemaFromResource(URL schemaURL)
  8. getXIncludeXMLReader()
  9. getXmlReader()