Validating xml against schema in java dive into the pool dating
package provides an API for XML documents validation.
The validation process verify that an XML document is an instance of a specified XML schema file or XSD file.
The problem I have is that the path to the schema is stored in the XML header and I can't knwo at run time where the schema is going to be.
Which is why it's stored in the XML file: ..Every example I see uses set Validating(true), which is now deprecated, so throws an exception.
The returned Schema object assumes that if documents refer to the same URL in the schema location hints, they will always resolve to the same schema document.
This asusmption allows implementations to reuse parsed results of schema documents so that multiple validations against the same schema will run faster.
Document; /** * A Utility to help with xml communication validation. Now if, as you say, includes b.xsd, and includes a.xsd, then there's no need to load all three into the schema factory. Not only is it unnecessary, it will likely confuse Xerces and result in errors, so this may be your problem. Just pass to the factory, and let it resolve and itself, which it should do relative to try catch (SAXException e) catch (IOException ex) class Validator extends Default Handler Remember to change: 1) The parameter " for you xsd file location.
XMLSchema Factory xml Schema Factory = new XMLSchema Factory(); Schema schema = xml Schema Schema(new Stream Source ); Validator validator = Validator(); validator.validate(new Stream Source(new String Reader(xml Content))); but this is failing to import all three of the schemas correctly resulting in cannot resolve the name 'blah' to a(n) 'group' component. 2) The string "/home/user/myfile.xml" for the one pointing to your xml file.