Package javax.xml.validation

Examples of javax.xml.validation.Validator.validate()


          // Only DOMSource and SAXSource are allowed for validating
          // See http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/Validator.html#validate(javax.xml.transform.Source,%20javax.xml.transform.Result)
          // As we expect a DOMResult as output, we must ensure that the input is a
          // DOMSource
          Source src = new SourceTransformer().toDOMSource(out.getContent());
            validator.validate(src, result);
            if (errorHandler.hasErrors()) {
                Fault fault = exchange.createFault();
                fault.setProperty("org.servicemix.schema", schema);
                fault.setContent(new DOMSource(result.getNode(), result.getSystemId()));
                throw new FaultException("Failed to validate against schema: " + schema, exchange, fault);
View Full Code Here


                    LOGGER.error("Error parsing Log4j schema", ex);
                }
                if (schema != null) {
                    final Validator validator = schema.newValidator();
                    try {
                        validator.validate(new StreamSource(new ByteArrayInputStream(buffer)));
                    } catch (final IOException ioe) {
                        LOGGER.error("Error reading configuration for validation", ioe);
                    } catch (final SAXException ex) {
                        LOGGER.error("Error validating configuration", ex);
                    }
View Full Code Here

            Validator validator = schema.newValidator();

            DOMSource source = new DOMSource(m_element);
            DOMResult result = new DOMResult();

            validator.validate(source, result);
            m_element = ((Document) result.getNode()).getDocumentElement();
        } catch (Exception exc) {
            System.err.println(exc);
            exc.printStackTrace();
        }
View Full Code Here

            public void error(SAXParseException exception) throws SAXException {
                validationErrors.add(exception);
            }

          });
        validator.validate(new DOMSource(dom));
        if (validationErrors != null && validationErrors.size() > 0) {
            StringBuilder sb = new StringBuilder();
            for (Exception ve : validationErrors) {
                sb.append(ve.getMessage()).append("\n");
            }
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

            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

            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

        // 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

                        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

        // 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));
    }

    /**
     *    
     * @param document
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.