Before upgrading, I was using JPMML version 1.4.15. I used to extract a PMML version from the pmml document and then to add the corresponding xsd file to the schema validation.
After upgrading JPMML to version 1.6.4, I’m no longer able to do that. I can only use my custom 4.4.xsd or the original one using JAXButil.getSchema() which uses the original 4-4.xsd file from the pmml-model jar.
If I try to use some version of xsd document below 4.4, I’m getting the following error:
*ERROR: PMML #69111 – Failed to create the PMML data model.
Schema validation errors:
cvc-elt.1.a: Cannot find the declaration of element ‘PMML’.
Technical Information:
ERROR: PMML #69114 – The PMML XML:*
My code (refactored to work only with xsd file version 4.4):
public static PMML createPMML(String pmmlXML) throws PMMLException
{
ValidationEventHandlerImpl errInserter = new ValidationEventHandlerImpl();
PMML answer = null;
try
{
pmmlXML = pmmlXML.trim();
byte[] pmmlBytes = pmmlXML.getBytes();
InputStream is = new ByteArrayInputStream(pmmlBytes);
ImportFilter filter = new ImportFilter();
Source source = SAXUtil.createFilteredSource(is, filter);
Unmarshaller unmarshaller = JAXBUtil.createUnmarshaller();
unmarshaller.setSchema(getSchema(pmmlXML));
unmarshaller.setEventHandler(errInserter);
answer = (PMML)unmarshaller.unmarshal(source);
}
catch(UnmarshalException ex)
{
//Error handling...
}
return answer;
}
public static Schema getSchema(String pmmlXML ) throws SAXException
{
Schema schema;
URL url = com.example.pmml.services.impl.PMMLEvaluator.class.getResource("/"+ xsdFile);
if(url == null)
{
PMMLLogger.processTechLogWrite(ERROR, String.format(
"Cannot open XSD for PMML version '4.4' for the PMML XML '%s'.", pmmlXML));
throw new RuntimeException("Cannot open XSD for PMML version 4.4.");
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schema = schemaFactory.newSchema(url);
return schema;
}
Surprisingly, all my tests pass when I use 4.4.xsd for schema validation even if I use different versions of pmml documents (3.0, 3.2, 4.0, 4.1, 4.2 and 4.3).
My questions:
Is it possible that all the versions of documents will work with xsd file version 4.4 (for schema validation)?
Do I miss something in the code that will allow to use xsd file version below 4.4?