boolean assertValid = getOption(_assert_valid,true);
boolean checkIdRefs = getOption(_dtd_id_idref_warnings,false);
boolean dtdAugment = getOption(_dtd_attribute_values,false);
ErrorHandler eh = new RNGErrorHandler();
PropertyMapBuilder properties = new PropertyMapBuilder();
properties.put(ValidateProperty.ERROR_HANDLER, eh);
properties.put(ValidateProperty.URI_RESOLVER, runtime.getResolver());
properties.put(ValidateProperty.ENTITY_RESOLVER, runtime.getResolver());
if (checkIdRefs) {
RngProperty.CHECK_ID_IDREF.add(properties);
}
XdmNode doc = source.read();
XdmNode schema = schemaSource.read();
XdmNode root = S9apiUtils.getDocumentElement(schema);
docBaseURI = doc.getBaseURI();
SchemaReader sr = null;
boolean compact = XProcConstants.c_data.equals(root.getNodeName());
String contentType = root.getAttributeValue(XProcConstants.c_content_type);
if (contentType != null) {
compact |= contentType.startsWith("text/") || contentType.equals("application/relax-ng-compact-syntax");
}
InputSource schemaInputSource = null;
JingConfigurer configurer = runtime.getConfigurer().getJingConfigurer();
if (compact) {
// Compact syntax
configurer.configRNC(properties);
sr = CompactSchemaReader.getInstance();
// Grotesque hack!
StringReader srdr = new StringReader(compactSchema(root));
schemaInputSource = new InputSource(srdr);
schemaInputSource.setSystemId(root.getBaseURI().toASCIIString());
} else {
// XML syntax
configurer.configRNG(properties);
sr = new AutoSchemaReader();
schemaInputSource = S9apiUtils.xdmToInputSource(runtime, schema);
}
ValidationDriver driver = new ValidationDriver(properties.toPropertyMap(), sr);
try {
if (driver.loadSchema(schemaInputSource)) {
InputSource din = S9apiUtils.xdmToInputSource(runtime, doc);
if (!driver.validate(din)) {
if (assertValid) {