I am working with XML
and JAXB
as I am unmarshalling and marshalling the XML into Java objects and vice versa. Now I am trying to validate our XML against our schema(test.xsd). Suppose if any required field is missing in my XML, then I would like to know which field is missing after validating the XML against schema test.xsd.
public void unmarshal(final InputStream is) {
final XMLInputFactory factory = XMLInputFactory.newInstance();
final XMLStreamReader reader = factory.createXMLStreamReader(is);
Object req = unmarshaller.unmarshal(reader);
// how would I validate here?
}
How would I validate my XML against test.xsd schema. My test.xsd schema path is -
C:\workspace\one\two\three\src\main\java\com\package\serv\ap\versionOne\test.xsd
UPDATE: loading test.xsd as:
Schema schema = factorySchema.newSchema(new File("C:\\workspace\\one\\two\\three\\src\\main\\java\\com\\package\\serv\\ap\\versionOne\\test.xsd"));