Skip to Content.
Sympa Menu

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

xom-interest AT

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Leif Stainsby <lstainsby AT>
  • To: XOM API for Processing XML with Java <xom-interest AT>
  • Subject: Re: [XOM-interest] validation after XInclude
  • Date: Tue, 25 Mar 2014 23:14:06 +0000

Hi M,

Typically one configures the parser to process the XIncludes it encounters
during parsing.
How this is configured depends on your parser, but, as an example, for Apache
Xerces you would use set the parser "feature" XInclude to be TRUE.
The parser "feature" name for the XInclude option is:

For more information see:

On that page is an example; here it is simplified even more:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature(" ", true);



-----Original Message-----
From: xom-interest-bounces AT
[mailto:xom-interest-bounces AT] On Behalf Of nu.xom AT
Sent: Tuesday, March 25, 2014 1:08 PM
To: xom-interest AT
Subject: [XOM-interest] validation after XInclude


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?

XOM-interest mailing list
XOM-interest AT

Archive powered by MHonArc 2.6.24.

Top of Page