Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] validation after XInclude

xom-interest AT

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: <nu.xom AT>
  • To: xom-interest AT
  • Subject: [XOM-interest] validation after XInclude
  • Date: Tue, 25 Mar 2014 20:08:06 +0000


I'm having a bit of a problem working out how to validate documents
containing XIncludes. Specifically, I'm only dealing with XSD schemas that
expect XIncludes to have been processed prior to validation. The
following code clearly doesn't do that:

final SAXParserFactory factory = SAXParserFactory.newInstance();

final InputStream xml_xsd =

try {
final InputStream schema_xsd =

try {
final SchemaFactory schema_factory =

final Source[] sources = new Source[2];
sources[0] = new StreamSource(xml_xsd);
sources[1] = new StreamSource(schema_xsd);

final TrivialErrorHandler handler = new TrivialErrorHandler();
final SAXParser parser = factory.newSAXParser();
final XMLReader reader = parser.getXMLReader();

final Builder builder = new Builder(reader);
final Document doc =;

if (handler.getException() != null) {
throw handler.getException();

final Document resolved = XIncluder.resolve(doc, builder);
if (handler.getException() != null) {
throw handler.getException();

return resolved;
} finally {
} finally {

I get validation errors like:

org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 75;
cvc-complex-type.2.4.a: Invalid content was found starting with element

So clearly, XIncludes aren't being processed before validation occurs.

I'm not exactly sure what the right sequence of steps is. Presumably
I need to parse, process XIncludes, and then validate. However, the
validation occurs (indirectly) via the Builder class, and if I've parsed
a document, then I've already missed the opportunity to validate...

What's the correct way to do this?


Archive powered by MHonArc 2.6.24.

Top of Page