You can probably do that with JDK API for Xml validation, if you use SAX-based writer: if so, just link in validator by calling 'Validator.validate(source, result)', where source comes from your writer, and result is where output needs to go.
As far as libraries goes, pretty much the de-facto standard is Xerces2 which has both C and Java versions.As of release 2.4.16, libxml2 passed all 1800 tests from the OASIS XML Tests Suite. You should not use the DOMParser to validate a document (unless your goal is to create a document object model anyway).I ended up using Liquid XML Studio 2008 (v6) which was much easier to use and more immediately familiar (the UI is very similar to Visual Basic 2008 Express, which I use frequently).The drawback: the validation capability is not in the free version, so I had to use the 30 day trial.As for a tool to do this for you, XMLFox seems to be a decent freeware solution, but not having used it personally I can't say for sure.
I had to validate an XML against XSD just one time, so I tried XMLFox. The help instructions didn't seem to match the interface.
W3C_XML_SCHEMA_NS_URI); // load a WXS schema, represented by a Schema instance Source schema File = new Stream Source(new File("my Schema.xsd")); Schema schema = Schema(schema File); // create a Validator instance, which can be used to validate an instance document Validator validator = Validator(); // validate the DOM tree try catch (SAXException e) Working this way, a SAXException would be thrown at the first error in the xml-file and stops then the validation. How do I recognize an error in the class that invokes the validate-method of my validator? If you are generating XML files programatically, you may want to look at the XMLBeans library.
Using a command line tool, XMLBeans will automatically generate and package up a set of Java objects based on an XSD.
@ziggy - this is an implementation detail of the JAXP implementation.
Sun's JDK 6 uses SAX parser with a Stream Source.
W3C_XML_SCHEMA_NS_URI); Schema schema = schema Schema(schema File); Validator validator = Validator(); try catch (SAXException e) but you could just as easily validate against a local file.