Package javax.xml.validation

Examples of javax.xml.validation.Validator


            }
        }

        // no need to synchronize, schema instances are thread-safe
        try {
            Validator validator = cachedSchema.newValidator();
            validator.setErrorHandler(errorHandler);

            // perform actual validation
            validator.validate(validateSrc);

            if (errorHandler.isValidationError()) {

                if (traceOrDebugOn) {
                    String msg = "Validation of element returned by XPath : " + source +
View Full Code Here


        }
       
        schemaFactory.setResourceResolver(JAVAEE_5_LS_RESOURCE_RESOLVER);
        Schema schema = schemaFactory.newSchema(schemaFile);

        Validator validator = schema.newValidator();
        URLConnection conn = xmlFile.openConnection();
        conn.setUseCaches(false);
        InputStream is = conn.getInputStream();
        Source source = new StreamSource(is);
        validator.setErrorHandler(VALIDATION_ERROR_HANDLER);
        validator.validate(source);
    }
View Full Code Here

            throw new IOException("Could not find schema file for validation.");
        }
        schemaFactory.setResourceResolver(ConfigFilesXmlValidationUtils.JAVAEE_5_LS_RESOURCE_RESOLVER);
        Schema schema = schemaFactory.newSchema(schemaFile);
   
        Validator validator = schema.newValidator();
        URLConnection conn = xmlFile.openConnection();
        conn.setUseCaches(false);
        InputStream is = conn.getInputStream();
        Source source = new StreamSource(is);
        validator.setErrorHandler(VALIDATION_ERROR_HANDLER);
        validator.validate(source);
    }
View Full Code Here

        }
    }

    public void validate(Schema schema) {
        try {
            Validator validator = schema.newValidator();
            for (Document doc : this.documents) {
                validator.validate(new DOMSource(doc));
            }
        } catch (Exception e) {
            throw new ComponentDefinitionException("Unable to validate xml", e);
        }
    }
View Full Code Here

        try {

            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(input);
            if(verifySchema) {
                Validator validator = schema.newValidator();
                validator.validate(new JDOMSource(doc));
            }
            Element root = doc.getRootElement();
            if(!root.getName().equals(STORES_ELMT))
                throw new MappingException("Invalid root element: "
                                           + doc.getRootElement().getName());
View Full Code Here

        @Override
        public SAXParseException[] validate(Source source, ValidationErrorHandler errorHandler) throws IOException {
            if (errorHandler == null) {
                errorHandler = new DefaultValidationErrorHandler();
            }
            Validator validator = schema.newValidator();
            validator.setErrorHandler(errorHandler);
            try {
                validator.validate(source);
                return errorHandler.getErrors();
            }
            catch (SAXException ex) {
                throw new XmlValidationException("Could not validate source: " + ex.getMessage(), ex);
            }
View Full Code Here

        xmlSchema = getSchemaFactory().newSchema(xmlSchemaURL);
      } catch(SAXException e) {
            throw XMLPlatformException.xmlPlatformErrorResolvingXMLSchema(xmlSchemaURL, e);       
      }
      try {
        Validator validator = xmlSchema.newValidator();
        validator.setErrorHandler(errorHandler);
        validator.validate(new DOMSource(document));
      } catch(Exception e) {
            throw XMLPlatformException.xmlPlatformValidationException(e);
      }
    return true;
    }
View Full Code Here

   public static void validate(final Node node, final String schemaFile) throws Exception
   {
      SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

      Schema schema = factory.newSchema(findResource(schemaFile));
      Validator validator = schema.newValidator();

      // validate the DOM tree
      try
      {
         validator.validate(new DOMSource(node));
      }
      catch (SAXException e)
      {
         HornetQClientLogger.LOGGER.errorOnXMLTransformInvalidConf(e);
View Full Code Here

    SchemaFactory factory = SchemaFactory
        .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Source schemaFile = new StreamSource(xsdFile);
    // log.info("Xsd=" + schemaFile.toString());
    Schema schema = factory.newSchema(schemaFile);
    Validator validator = schema.newValidator();
    try
    {
      validator.validate(new DOMSource(document));
      isValid = true;
    }
    catch (SAXException e)
    {
      log.error("Failed to validate xml", e);
View Full Code Here

    private void validate(final String xml) throws ActionProcessingException
    {
        try
        {
            final Validator validator = schema.newValidator();
            validator.validate(createSourceFromPayload(xml));
        }
        catch (final SAXException e)
        {
            final String errorMsg = "SAXException while trying to validate against schema '" + xsd + "'";
            log.error(errorMsg, e);
View Full Code Here

TOP

Related Classes of javax.xml.validation.Validator

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.