Java 8 Schema - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Schema class.

This code example shows how to use the following methods:newValidator
        Validator validator = null;
        InputStream xsdStream = SdkAddonConstants.getXsdStream(version);
        if (xsdStream != null) {
            SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = factory.newSchema(new StreamSource(xsdStream));
            validator = schema.newValidator();
            if (handler != null) {
                validator.setErrorHandler(handler);
            } 
        } 
 
        return validator;
    } 
 
    /** An helper that validates a string against an expected regexp. */ 
    private void assertRegex(String expectedRegexp, String actualString) {
        assertNotNull(actualString);
        assertTrue(
                String.format("Regexp Assertion Failed:\nExpected: %s\nActual: %s\n",
                        expectedRegexp, actualString),
6
CodeRank
This code example shows how to use the following methods:newValidator
This code example shows how to use the following methods:newValidator
        dbf.setSchema(schema);
 
        builder = dbf.newDocumentBuilder();
        builder.setErrorHandler(handler);
        builder.setEntityResolver(handler);
        validator = schema.newValidator();
    } 
 
    @Override 
    protected void tearDown() throws Exception { 
        builder = null;
        validator = null;
        super.tearDown(); 
    } 
 
    public void testParserBadXML() { 
        System.out.println("-- testParserBadXML");
        try { 
            builder.parse(getAsStream(BAD_XML));
            assertTrue(true); 
6
CodeRank
This code example shows how to use the following methods:newValidator
    } 
     
    private void validateXML(String xml,java.io.InputStream schemaIn) throws Exception {
    	SchemaFactory sf=SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    	Schema schema=sf.newSchema(new StreamSource(schemaIn));
    	Validator validator=schema.newValidator();
    	StringBuilder errorBuilder=new StringBuilder();
    	try{ 
    		validator.validate(new StreamSource(new StringReader(xml)));
    	}catch (Exception e) {
    		e.printStackTrace();
    		fail("Error during validation of XML:\n" + e.getLocalizedMessage());
		} 
    } 
 
 
    /** 
     * Explicit RELS-EXT relation to collection object 
     * @throws Exception 
     */ 
6
CodeRank
This code example shows how to use the following methods:newValidator
            log.debug("Attempt to validate xml at: " + galleryItemUrl + "with xsd at: " + xsdPath);
 
            SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaString);
            Schema schema = schemaFactory.newSchema(new StreamSource(schemaStream));
 
            Validator validator = schema.newValidator();
 
            // TODO: stuff the input stream into the context for execute() 
            InputStream galleryItemInputStream = xmlFetcher.getInputStream(galleryItemUrl);
 
            validator.validate(new StreamSource(galleryItemInputStream));
 
            log.debug("Success validating xml at: " + galleryItemUrl);
        } 
        catch (Exception e)
        { 
            log.error("Validation for gadget definition failed.", e);
            ValidationException ve = new ValidationException();
            ve.addError(URL_KEY, "Valid url is required");
            throw ve;
5
CodeRank
This code example shows how to use the following methods:newValidator
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 )
        { 
            throw new SchemaValidatorException( "IOException : " + e.getMessage(), e );
5
CodeRank
This code example shows how to use the following methods:newValidatorHandler
			JDOMException { 
		// NOTE: Create a schema object without schema file name so that schemas 
		// will be obtained from whatever locations are provided in the document 
 
		Schema schema = factory.newSchema();
		ValidatorHandler vh = schema.newValidatorHandler();
		so = new SAXOutputter(vh);
		so.output(xml);
	} 
 
	// --------------------------------------------------------------------------- 
	// --- 
	// --- Variables 
	// --- 
	// --------------------------------------------------------------------------- 
 
	private static SchemaFactory factory = SchemaFactory
			.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
	private static SAXOutputter so;
 
5
CodeRank
This code example shows how to use the following methods:newValidator
		{ 
			throw new RuntimeException(e);
		} 
 
		// 3. Get a validator from the schema. 
		Validator validator = schema.newValidator();
 
		// 4. Parse the document you want to check. 
		Source source = new StreamSource(xmlFile);
 
		// 5. Check the document 
		XsdValidationResult result;
		try 
		{ 
			validator.validate(source);
			result = new XsdValidationResult(true, xmlFile.getName() + " is valid.");
		} 
		catch (SAXException ex)
		{ 
			result = new XsdValidationResult(false, xmlFile.getName() + " is not valid because: " + ex.getMessage());
5
CodeRank
This code example shows how to use the following methods:newValidator
            versionString = expr.evaluate(doc);
        } catch (XPathExpressionException e) {
            throw new IOException(e); // this should not happen
        } 
        Schema schema = versionMapUR.get(versionString);
        Validator val = schema.newValidator();
        try { 
            val.validate(new DOMSource(doc));
        } catch (SAXException e) {
            throw new IOException(e); // this should not happen
        } 
         
    } 
 
    /** 
     * Validates a Role DOM against the XMLSchema. 
     * The schema is determined by the version of the  
     * Role DOM  
     *  
     * @param doc 
5
CodeRank
This code example shows how to use the following methods:newValidator
        dbf.setSchema(schema);
 
        builder = dbf.newDocumentBuilder();
        builder.setErrorHandler(handler);
        builder.setEntityResolver(handler);
        validator = schema.newValidator();
    } 
 
    @Override 
    protected void tearDown() throws Exception {
        builder = null;
        validator = null;
        super.tearDown(); 
    } 
 
    public void testParserBadXML() { 
        System.out.println("-- testParserBadXML");
        try { 
            builder.parse(getAsStream(BAD_XML));
            assertTrue(true); 
5
CodeRank

Related Java 8 Schema Questions & Answers:

See Code Examples for Java 8 Schema Methods: