use of org.apache.xmlbeans.XmlOptions in project knime-core by knime.
the class PMMLValidator method validatePMML.
/**
* Validates a document against the schema and returns the number of
* errors found.
*
* @param pmmlDocument the PMMML document
* @return the error message or an em
*/
public static Map<String, String> validatePMML(final PMMLDocument pmmlDocument) {
XmlOptions validateOptions = new XmlOptions();
List<XmlError> errorList = new ArrayList<XmlError>();
validateOptions.setErrorListener(errorList);
pmmlDocument.validate(validateOptions);
Map<String, String> errorMessages = new TreeMap<String, String>();
for (XmlError error : errorList) {
String location = error.getCursorLocation().xmlText();
if (location.length() > 50) {
location = location.substring(0, 50) + "[...]";
}
String errorMessage = error.getMessage().replace(PMML_NAMESPACE_URI, "");
LOGGER.error(location + ": " + errorMessage);
errorMessages.put(location, errorMessage);
}
return errorMessages;
}
Aggregations