Yes, you can use the validator found in java from 1.5. here is the doc link
In addition, you can use the dom-based or stream based APIs to validate your XML document in the xsd file. If you want to use the SAX API for your task, then hear an example:
try { String schemaLang = "http://www.w3.org/2001/XMLSchema"; SchemaFactory factory = SchemaFactory.newInstance(schemaLang); Schema schema = factory.newSchema(new StreamSource("sample.xsd")); Validator validator = schema.newValidator(); validator.validate(new StreamSource("test.xml")); } catch (SAXException e) { System.out.println(" sax exception :" + e.getMessage()); } catch (Exception ex) { System.out.println("excep :" + ex.getMessage()); }
Otherwise, you can use the DOM, DOM4J, or XOM API. For further links you can see here .
There is also a related answer in stackoverflow.
Forhad
source share