Skip to Content.
Sympa Menu

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

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

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

'Lo.

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();
factory.setValidating(false);
factory.setNamespaceAware(true);
factory.setXIncludeAware(true);

final InputStream xml_xsd =
SVersion.class.getResourceAsStream("/com/io7m/jstructural/xml.xsd");

try {
final InputStream schema_xsd =
SVersion.class
.getResourceAsStream("/com/io7m/jstructural/schema.xsd");

try {
final SchemaFactory schema_factory =
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema";);

final Source[] sources = new Source[2];
sources[0] = new StreamSource(xml_xsd);
sources[1] = new StreamSource(schema_xsd);
factory.setSchema(schema_factory.newSchema(sources));

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

final Builder builder = new Builder(reader);
final Document doc = builder.build(stream);

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

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

return resolved;
} finally {
schema_xsd.close();
}
} finally {
xml_xsd.close();
}

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
'xi:xinclude'.

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?

M




Archive powered by MHonArc 2.6.24.

Top of Page