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: <nu.xom AT io7m.com>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] validation after XInclude
  • Date: Wed, 26 Mar 2014 10:21:30 +0000

On Tue, 25 Mar 2014 23:14:06 +0000
Leif Stainsby <lstainsby AT galdosinc.com> wrote:

> Hi M,
>
> Typically one configures the parser to process the XIncludes it encounters
> during parsing.

'Lo.

Thanks very much. For the record, the code is now:

final SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
factory.setXIncludeAware(true);
factory.setFeature("http://apache.org/xml/features/xinclude";, 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();
}

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

According to the xerces docs:

reader.setFeature("http://apache.org/xml/features/xinclude";, true);

Would work too.

M




Archive powered by MHonArc 2.6.24.

Top of Page