Package javax.xml.validation

Examples of javax.xml.validation.Validator


    private static void validate(Document doc, String schemaLocation) throws SAXException {
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        // root element has namespace - we can use schema validation
        Schema schema = factory.newSchema(new StreamSource(FeatureValidationUtil.class.getResourceAsStream(schemaLocation)));
        // create schema by reading it from an XSD file:
        Validator validator = schema.newValidator();
        try {
            validator.validate(new DOMSource(doc));
        } catch (Exception e) {
            throw new IllegalArgumentException("Unable to validate " + doc.getDocumentURI(), e);
        }
    }
View Full Code Here


    private SchemaValidatingMatcher() {
    }

    @Override
    protected boolean matchesSafely(final String item, final Description mismatchDescription) {
        final Validator validator;
        try {
            validator = SCHEMA_VALIDATOR_SOURCE.validator();
        } catch (SAXException e) {
            throw new IllegalStateException("Unable to instantiate validator", e);
        }
        try {
            validator.validate(new StreamSource(new StringReader(item)));
            return true;
        } catch (SAXException e) {
            mismatchDescription.appendText(e.getLocalizedMessage());
            return false;
        } catch (IOException e) {
View Full Code Here

                log.debug("Schemas have not been specified..");
                schema = factory.newSchema();
            }

            // Setup validator and input source.
            Validator validator = schema.newValidator();
            validator.setErrorHandler(handler);
            validator.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true);
            validator.setFeature(HONOUR_ALL_SCHEMA_LOCATIONS_ID, true);

            XMLReader reader = XMLReaderFactory.createXMLReader();
            SAXSource source = new SAXSource(reader, new InputSource(baisFromSource));
            validator.validate(source);

            if (handler.isValidationError()) {
                log.debug("Validation of element : " + sourceNode + " failed against : " + schemaUrl +
                    " Message : " + handler.getSaxParseException().getMessage() + " Executing 'on-fail' sequence");
                log.debug("Failed message envelope : " + synCtx.getEnvelope());
View Full Code Here

        // root element has namespace - we can use schema validation
        Schema schema = factory.newSchema(new StreamSource(FeatureValidationUtil.class
            .getResourceAsStream(schemaLocation)));

        // create schema by reading it from an XSD file:
        Validator validator = schema.newValidator();

        try {
            validator.validate(new DOMSource(doc));
        } catch (Exception e) {
            throw new IllegalArgumentException("Unable to validate " + doc.getDocumentURI(), e);
        }       
    }
View Full Code Here

                        // get the value child of the property element
                        Document property = (Document)componentProperty.getValue();
                        Element value = (Element)property.getDocumentElement().getFirstChild();
               
                        // validate the element property/value from the DOM
                        Validator validator = schema.newValidator();
                        validator.validate(new DOMSource(value));
                       
                    } catch (Exception e) {
                        Monitor.error(monitor,
                                this,
                                Messages.ASSEMBLY_VALIDATION,
View Full Code Here

        // load a WXS schema, represented by a Schema instance
        Source schemaFileSource = new StreamSource(schemaFile);
        Schema schema = factory.newSchema(schemaFileSource);

        // create a Validator instance, which can be used to validate an instance document
        Validator validator = schema.newValidator();

        // validate the DOM tree
        validator.validate(new DOMSource(document));
    }
View Full Code Here

        // load a WXS schema, represented by a Schema instance
        Source schemaFileSource = new StreamSource(schemaFile);
        Schema schema = factory.newSchema(schemaFileSource);

        // create a Validator instance, which can be used to validate an instance document
        Validator validator = schema.newValidator();

        // validate the DOM tree
        validator.validate(new DOMSource(document));
    }
View Full Code Here

        {
            String schemaPath = CHANGES_SCHEMA_PATH + "changes-" + schemaVersion + ".xsd";

            Schema schema = getSchema( schemaPath );

            Validator validator = schema.newValidator();

            XmlValidationHandler baseHandler = new XmlValidationHandler( failOnValidationError );

            validator.setErrorHandler( baseHandler );

            reader = new XmlStreamReader( file );

            validator.validate( new StreamSource( reader ) );

            return baseHandler;
        }
        catch ( IOException e )
        {
View Full Code Here

  public static boolean validateResultStructure(OMElement result,
      String schemaPath) throws Exception {
    SchemaFactory fac = SchemaFactory.newInstance(XSD_SCHEMA);
    Source source = new StreamSource(new FileInputStream(schemaPath));
    Schema schema = fac.newSchema(source);
    Validator validator = schema.newValidator();
    try {
      validator.validate(new StreamSource(new StringReader(result
          .toString())));
    } catch (Exception e) {
      return false;
    }
    return true;
View Full Code Here

            SchemaFactory factory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
            // load a WXS schema, represented by a Schema instance
            Source schemaFile = new StreamSource(xsdContent);
            Schema schema = factory.newSchema(schemaFile);
            // create a Validator instance, which can be used to validate an instance document
            Validator validator = schema.newValidator();
            // validate the DOM tree
            validator.validate(scoure);
            resource.setProperty(XSD_STATUS, XSD_VALID);
        } catch (Exception e) {
            resource.setProperty(XSD_STATUS, XSD_IN_VALID);
            resource.addProperty(XSD_VALIDATION_ERROR, e.getMessage());
            throw new RegistryException(e.getMessage());
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.