Permalink
Browse files

Check for bad schema input and report a useful error message

  • Loading branch information...
ndw committed Dec 15, 2011
1 parent 65cf8a6 commit 53ca7f172192f3e7376285c324cfcae364fdbdf0
Showing with 10 additions and 1 deletion.
  1. +10 −1 src/com/xmlcalabash/library/ValidateWithSCH.java
@@ -87,6 +87,8 @@ public void run() throws SaxonApiException {
// If we're dealing with a typed document, we must compile the XSLT in schema-aware mode
schemaAware = (sourceXML.getUnderlyingNode().getTypeAnnotation() != StandardNames.XS_UNTYPED);
XdmNode schemaXML = schema.read();
XsltCompiler compiler;
XsltExecutable exec;
XdmDestination result;
@@ -102,7 +104,7 @@ public void run() throws SaxonApiException {
// It would be nice to load these stylesheets only once, but sometimes (i.e. from RunTest),
// there are different controllers involved and you can't do that.
XdmNode theSchema1_sch = transform(schema.read(), getSchematronXSLT("iso_dsdl_include.xsl"));
XdmNode theSchema1_sch = transform(schemaXML, getSchematronXSLT("iso_dsdl_include.xsl"));
XdmNode theSchema2_sch = transform(theSchema1_sch, getSchematronXSLT("iso_abstract_expand.xsl"));
skeleton = getClass().getResourceAsStream("/etc/schematron/iso_schematron_skeleton_for_saxon.xsl");
@@ -135,6 +137,13 @@ public void run() throws SaxonApiException {
schemaCompiler.transform();
XdmNode compiledSchema = result.getXdmNode();
XdmNode compiledRoot = S9apiUtils.getDocumentElement(compiledSchema);
if (compiledRoot == null) {
XdmNode schemaRoot = S9apiUtils.getDocumentElement(schemaXML);
String root = schemaRoot == null ? "null" : schemaRoot.getNodeName().toString();
throw new XProcException("p:validate-with-schematron failed to compile provided schema: " + root);
}
XsltTransformer transformer;

0 comments on commit 53ca7f1

Please sign in to comment.