Search in sources :

Example 36 with XmlOptions

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;
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions) ArrayList(java.util.ArrayList) XmlError(org.apache.xmlbeans.XmlError) TreeMap(java.util.TreeMap)

Aggregations

XmlOptions (org.apache.xmlbeans.XmlOptions)36 OutputStream (java.io.OutputStream)18 QName (javax.xml.namespace.QName)18 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)17 XmlException (org.apache.xmlbeans.XmlException)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 Beta (org.apache.poi.util.Beta)7 XmlError (org.apache.xmlbeans.XmlError)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 HashMap (java.util.HashMap)2 MarshalException (javax.xml.crypto.MarshalException)2 EncryptedDocumentException (org.apache.poi.EncryptedDocumentException)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 XmlObject (org.apache.xmlbeans.XmlObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 GeneralSecurityException (java.security.GeneralSecurityException)1