Skip to Content.
Sympa Menu

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

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Leif Stainsby <lstainsby AT galdosinc.com>
  • To: XOM API for Processing XML with Java <xom-interest AT lists.ibiblio.org>
  • 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:
http://apache.org/xml/features/xinclude

For more information see: http://xerces.apache.org/xerces2-j/features.html

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

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature("http://apache.org/xml/features/xinclude ", true);

Cheers,

...Leif

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

'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
_______________________________________________
XOM-interest mailing list
XOM-interest AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/xom-interest




Archive powered by MHonArc 2.6.24.

Top of Page