use of com.helger.schematron.pure.binding.IPSQueryBinding in project ph-schematron by phax.
the class DocumentationExamples method validateXMLViaPureSchematron2.
public static boolean validateXMLViaPureSchematron2(@Nonnull final File aSchematronFile, @Nonnull final File aXMLFile) throws Exception {
// Read the schematron from file
final PSSchema aSchema = new PSReader(new FileSystemResource(aSchematronFile)).readSchema();
if (!aSchema.isValid(new DoNothingPSErrorHandler()))
throw new IllegalArgumentException("Invalid Schematron!");
// Resolve the query binding to use
final IPSQueryBinding aQueryBinding = PSQueryBindingRegistry.getQueryBindingOfNameOrThrow(aSchema.getQueryBinding());
// Pre-process schema
final PSPreprocessor aPreprocessor = new PSPreprocessor(aQueryBinding);
aPreprocessor.setKeepTitles(true);
final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema(aSchema);
// Bind the pre-processed schema
final IPSBoundSchema aBoundSchema = aQueryBinding.bind(aPreprocessedSchema, null, null, null, null);
// Read the XML file
final Document aXMLNode = DOMReader.readXMLDOM(aXMLFile);
if (aXMLNode == null)
return false;
// Perform the validation
return aBoundSchema.validatePartially(aXMLNode, FileHelper.getAsURLString(aXMLFile)).isValid();
}
use of com.helger.schematron.pure.binding.IPSQueryBinding in project ph-schematron by phax.
the class PSBoundSchemaCacheKey method createBoundSchema.
/**
* The main routine to create a bound schema from the passed resource and
* phase. The usual routine is to
* <ol>
* <li>read the schema from the resource - see
* {@link #readSchema(IReadableResource, IPSErrorHandler, EntityResolver)}</li>
* <li>resolve the query binding - see {@link #getQueryBinding(PSSchema)}</li>
* <li>pre-process the schema -
* {@link #createPreprocessedSchema(PSSchema, IPSQueryBinding)}</li>
* <li>and finally bind it -
* {@link IPSQueryBinding#bind(PSSchema, String, IPSErrorHandler, javax.xml.xpath.XPathVariableResolver, javax.xml.xpath.XPathFunctionResolver)}
* </li>
* </ol>
*
* @return The bound schema. Never <code>null</code>.
* @throws SchematronException
* In case reading or binding fails.
*/
@Nonnull
public IPSBoundSchema createBoundSchema() throws SchematronException {
// Read schema from resource
final PSSchema aSchema = readSchema(getResource(), getErrorHandler(), getEntityResolver());
// Resolve the query binding to be used
final IPSQueryBinding aQueryBinding = getQueryBinding(aSchema);
// Pre-process schema
final PSSchema aPreprocessedSchema = createPreprocessedSchema(aSchema, aQueryBinding);
// And finally bind the pre-processed schema
return aQueryBinding.bind(aPreprocessedSchema, getPhase(), getErrorHandler(), getVariableResolver(), getFunctionResolver());
}
Aggregations