Package javax.xml.validation

Examples of javax.xml.validation.SchemaFactory


    // START SNIPPET: sax
    public void validate(InputStream in, URL schemaUrl) throws Exception {
        SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(in, "UTF-8");
        SOAPEnvelope envelope = builder.getSOAPEnvelope();
        OMElement bodyContent = envelope.getBody().getFirstElement();
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(schemaUrl);
        Validator validator = schema.newValidator();
        validator.validate(bodyContent.getSAXSource(true));
    }
View Full Code Here


    public void validateUsingDOM(InputStream in, URL schemaUrl) throws Exception {
        OMMetaFactory mf = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM);
        SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(mf, in, "UTF-8");
        SOAPEnvelope envelope = builder.getSOAPEnvelope();
        OMElement bodyContent = envelope.getBody().getFirstElement();
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(schemaUrl);
        Validator validator = schema.newValidator();
        validator.validate(new DOMSource((Element)bodyContent));
    }
View Full Code Here

     * @throws ParserConfigurationException If a {@link DocumentBuilder} cannot be created which satisfies the
     *             configuration requested.
     * @throws IOException If any IO errors occur.
     */
    public static Configuration create (final File schemaLocation, final File configFile, final String pTargetAddress) throws SAXException , ParserConfigurationException , IOException {
        final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        final Schema schema = schemaFactory.newSchema(schemaLocation);

        // create a validator for the document
        final Validator validator = schema.newValidator();

        final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
View Full Code Here

     *             configuration requested.
     * @throws IOException If any IO errors occur.
     */
    private final Document parse (final File schemaLocation, final File configFile) throws ConfigurationException {
        try {
            final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            final Schema schema = schemaFactory.newSchema(schemaLocation);

            // create a validator for the document
            final Validator validator = schema.newValidator();

            final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
View Full Code Here

    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 ) {
      throw new XmlParsingException( "Unable to create schema for " + schemaName + ": " + e.getMessage(), e );
    }
    return schema;
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
      {
View Full Code Here

    private static class KieModuleValidator {
        private static final Schema schema = loadSchema();

        private static Schema loadSchema() {
            SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
            try {
                URL url = KieModuleModel.class.getClassLoader().getResource("org/kie/api/kmodule.xsd");
                return factory.newSchema(url);
            } catch (SAXException ex ) {
                throw new RuntimeException( "Unable to load XSD", ex );
            }
        }
View Full Code Here

      DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
      documentBuilderFactory.setNamespaceAware(true);
      DocumentBuilder parser = documentBuilderFactory.newDocumentBuilder();
      Document document = parser.parse(inputStreamXml);

      SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      InputStream schemaStream = ResourceLoader.getResourceAsStream("nifty-1.3.xsd");
      try {
        Source schemaFile = new StreamSource(schemaStream);
        javax.xml.validation.Schema schema = factory.newSchema(schemaFile);
        javax.xml.validation.Validator validator = schema.newValidator();
        validator.validate(new DOMSource(document));
      } finally {
        schemaStream.close();
      }
View Full Code Here

    private static class KieModuleValidator {
        private static final Schema schema = loadSchema();

        private static Schema loadSchema() {
            SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
            try {
                URL url = KieModuleModel.class.getClassLoader().getResource("org/kie/api/kmodule.xsd");
                return factory.newSchema(url);
            } catch (SAXException ex ) {
                throw new RuntimeException( "Unable to load XSD", ex );
            }
        }
View Full Code Here

    }
    try {
      InputStream schemaStream = url.openStream();
      try {
        StreamSource source = new StreamSource( url.openStream() );
        SchemaFactory schemaFactory = SchemaFactory.newInstance( schemaLanguage );
        return schemaFactory.newSchema( source );
      }
      catch ( SAXException e ) {
        throw new XsdException( "Unable to load schema [" + schemaName + "]", e, schemaName );
      }
      catch ( IOException e ) {
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.