Package javax.xml.validation

Examples of javax.xml.validation.SchemaFactory


    URL schemaUrl = this.getClass().getClassLoader().getResource( schemaName );
    if ( schemaUrl == null ) {
      return schema;
    }

    SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
    try {
      schema = sf.newSchema( schemaUrl );
    }
    catch ( SAXException e ) {
      context.logMessage(
          Diagnostic.Kind.WARNING, "Unable to create schema for " + schemaName + ": " + e.getMessage()
      );
View Full Code Here


        return factory;
    }

    public static SchemaFactory createSchemaFactory(String uri) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        SchemaFactory factory;
        try {
            Thread.currentThread().setContextClassLoader(Util.class.getClassLoader());
            factory = SchemaFactory.newInstance(uri);
        } finally {
            Thread.currentThread().setContextClassLoader(cl);
View Full Code Here

        filexsd.createNewFile();
        FileWriter writer = new FileWriter(filexsd);
        filexsd = generateXSD(writer, dir, metadataALL, filexsd, null);

        // create xsd validator
        SchemaFactory factory = SchemaFactory
                .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Source schemaSource = new StreamSource(filexsd);

        Schema schema = factory.newSchema(schemaSource);
        // validate source xml to xsd
        Validator validator = schema.newValidator();
        validator.validate(new StreamSource(filexml));

        // parse xml to dom
View Full Code Here

        FileWriter writer = new FileWriter(filexsd);
        filexsd = generateGrantXSD(writer, dir, metadataALL, filexsd,
                new String[] { "grants", "grant" });

        // create xsd validator
        SchemaFactory factory = SchemaFactory
                .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Source schemaSource = new StreamSource(filexsd);

        Schema schema = factory.newSchema(schemaSource);
        // validate source xml to xsd
        Validator validator = schema.newValidator();
        validator.validate(new StreamSource(filexml));

        // parse xml to dom
View Full Code Here

      ClassLoader tcl = SecurityActions.getContextClassLoader();
      URL schemaURL = tcl.getResource(schemaLocation);
      if(schemaURL == null)
         throw new IllegalStateException("Schema URL is null:" + schemaLocation);

      SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      return factory.newSchema(schemaURL);
   }
View Full Code Here

    * @throws IOException any IOException thrown by using the provided URL
    * @throws NullPointerException if the provided URL is null
    */
   public boolean isValid(URL url) throws NullPointerException, IOException
   {
      SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      URL schemaURL = getClass().getResource("kernel-configuration_1_0.xsd");
      if (schemaURL != null)
      {
         try
         {
            Schema schema = factory.newSchema(schemaURL);
            Validator validator = schema.newValidator();
            Reporter reporter = new Reporter(url);
            validator.setErrorHandler(reporter);

            // Validate the document
View Full Code Here

         NamespaceFilter nf = new NamespaceFilter();
         XMLReader reader = XMLReaderFactory.createXMLReader();
         nf.setParent(reader);

         if (schema != null) {
            SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
            u.setSchema(factory.newSchema(new StreamSource(schema)));
            u.setEventHandler(new ValidationEventHandler() {
               @Override
               public boolean handleEvent(ValidationEvent event) {
                  int severity = event.getSeverity();
                  return (severity != ValidationEvent.FATAL_ERROR && severity != ValidationEvent.ERROR);
View Full Code Here

    }
    try {
      InputStream schemaStream = url.openStream();
      try {
        StreamSource source = new StreamSource( url.openStream() );
        SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
        return schemaFactory.newSchema( source );
      }
      catch ( SAXException e ) {
        throw new XsdException( "Unable to load schema [" + schemaName + "]", e, schemaName );
      }
      catch ( IOException e ) {
View Full Code Here

         NamespaceFilter nf = new NamespaceFilter();
         XMLReader reader = XMLReaderFactory.createXMLReader();
         nf.setParent(reader);

         if (schema != null) {
            SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
            u.setSchema(factory.newSchema(new StreamSource(schema)));
            u.setEventHandler(new ValidationEventHandler() {
               @Override
               public boolean handleEvent(ValidationEvent event) {
                  int severity = event.getSeverity();
                  return (severity != ValidationEvent.FATAL_ERROR && severity != ValidationEvent.ERROR);
View Full Code Here

    try {
      InputStream schemaStream = schemaUrl.openStream();
      try {
        StreamSource source = new StreamSource(schemaUrl.openStream());
        SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
        return schemaFactory.newSchema(source);
      }
      catch ( Exception e ) {
        throw new XmlInfrastructureException( "Unable to load schema [" + schemaUrl.toExternalForm() + "]", e );
      }
      finally {
View Full Code Here

TOP

Related Classes of javax.xml.validation.SchemaFactory

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.