1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
// create a SchemaFactory capable of understanding WXS
schemas
SchemaFactory factory = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(new File(
"catalogue.xsd"));
Schema schema;
try {
schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to
// validate an instance document
Validator validator = schema.newValidator();
// validate the DOM tree
try {
try {
validator.validate(new DOMSource(dom));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (SAXException e) {
// instance document is invalid!
e.printStackTrace();
System.out.println("document pas cool");
try {
serializer.serialize(dom);
} catch (IOException eo) {
// TODO Auto-generated catch block
eo.printStackTrace();
}
return new String(os.toByteArray());
}
} catch (SAXException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} |
Partager