Search in sources :

Example 6 with XmlError

use of org.apache.xmlbeans.XmlError in project knime-core by knime.

the class NodeDescription28Proxy method validate.

/**
 * Validate against the XML Schema. If violations are found they are reported via the logger as coding problems.
 *
 * @return <code>true</code> if the document is valid, <code>false</code> otherwise
 */
protected final boolean validate() {
    // this method has default visibility so that we can use it in testcases
    XmlOptions options = new XmlOptions(OPTIONS);
    List<XmlError> errors = new ArrayList<XmlError>();
    options.setErrorListener(errors);
    boolean valid = m_document.validate(options);
    if (!valid) {
        logger.coding("Node description of '" + m_document.getKnimeNode().getName() + "' does not conform to the Schema. Violations follow.");
        for (XmlError err : errors) {
            logger.coding(err.toString());
        }
    }
    return valid;
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions) ArrayList(java.util.ArrayList) XmlError(org.apache.xmlbeans.XmlError)

Example 7 with XmlError

use of org.apache.xmlbeans.XmlError 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

ArrayList (java.util.ArrayList)7 XmlError (org.apache.xmlbeans.XmlError)7 XmlOptions (org.apache.xmlbeans.XmlOptions)7 TreeMap (java.util.TreeMap)1