Created
August 11, 2014 13:04
-
-
Save acmi/e2ebae96dd3cf9d883b6 to your computer and use it in GitHub Desktop.
JAXBValidator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import classes.Products; | |
import javax.xml.XMLConstants; | |
import javax.xml.bind.JAXBContext; | |
import javax.xml.bind.util.JAXBSource; | |
import javax.xml.transform.Source; | |
import javax.xml.validation.Schema; | |
import javax.xml.validation.SchemaFactory; | |
import javax.xml.validation.Validator; | |
import java.io.File; | |
public class JAXBValidator { | |
public static void main(String[] args) throws Exception{ | |
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); | |
Schema schema = sf.newSchema(new File("products.xsd")); | |
JAXBContext context = JAXBContext.newInstance(Products.class); | |
JAXBSource source = new JAXBSource(context, null); | |
Validator validator = schema.newValidator(); | |
validator.validate(new Source() { | |
@Override | |
public void setSystemId(String systemId) { | |
} | |
@Override | |
public String getSystemId() { | |
return null; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment