use of org.nextprot.api.commons.utils.XMLPrettyPrinter in project nextprot-api by calipho-sib.
the class XSDValidationTest method shouldValidateXMLFilewithXSD.
@Test
public void shouldValidateXMLFilewithXSD() {
Schema schema;
try {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schema = factory.newSchema(new StreamSource(new File("src/main/webapp/nextprot-export-v2.xsd")));
File f = new File("tmp.xml");
StreamSource xmlFile = new StreamSource(f);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
streamEntryService.streamEntries(Collections.singletonList("NX_Q15858"), NextprotMediaType.XML, "entry", baos, "");
XMLPrettyPrinter prettyPrinter = new XMLPrettyPrinter();
String prettyXml = prettyPrinter.prettify(baos.toString());
PrintWriter out = new PrintWriter(f);
out.print(prettyXml);
out.close();
// instance document
Validator validator = schema.newValidator();
// validate the DOM tree
validator.validate(xmlFile);
f.delete();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations