Castor and JAXB are other Java libraries that serve a similar purpose to XMLBeans. The definition of the dtd and xsd has to be in the xml! Be fore warned though, it is a heavy weight solution.But then again, validating XML against XSD files is a rather heavy weight problem.
@ziggy - this is an implementation detail of the JAXP implementation.
This will start creating DOM objects as it parses the document - wasteful if you aren't going to use them.
Also current features such as are available in Angle Sharp.
Also the parser uses the HTML 5.1 specification, which defines error handling and element correction.
Or you can set your own via set Resource Resolver, ex: Source xml File = new Stream Source(xml File Location); Schema Factory schema Factory = Schema Factory Instance(XMLConstants.