I have found a workaround by using a custom ValidationEventHandler:

/**
 * Handler will log all validation events depending on the current log
level. It will not break the marshaling process.
 * Instead of that it will cache the first error validation event. It can be
evaluated after marshaling finished.
 * 
 * Attention: The event handler is stateful and not thread safe.
 *
 */
public class MyValidationEventHandler implements ValidationEventHandler {

        private static final Logger LOGGER =
Logger.getLogger(MyValidationEventHandler .class);

        /**
         * Holds the first error validation event. It will be handled after
marshaling was completed.
         */
        private ValidationEvent firstErrorValidationEvent;

        /**
         * @return Always returns <code>true</code>, because we want to continue
the current unmarshal, validate, or marshal
         *         to log all events.
         */
        @Override
        public boolean handleEvent(ValidationEvent event) {
                if (firstErrorValidationEvent == null && event.getSeverity() >
ValidationEvent.WARNING) {
                        firstErrorValidationEvent = event;
                }

                switch (event.getSeverity()) {
                case ValidationEvent.WARNING:
                        LOGGER.warn("Validation warning: " + event.toString());
                        break;
                case ValidationEvent.ERROR:
                case ValidationEvent.FATAL_ERROR:
                        LOGGER.error("Validation error: " + event.toString());
                        break;
                default:
                        LOGGER.info("Validation event: " + event.toString());
                }

                return true;
        }

        public ValidationEvent getFirstErrorValidationEvent() {
                return firstErrorValidationEvent;
        }

}




--
View this message in context: 
http://apache-xml-project.6118.n7.nabble.com/XMLSchemaValidator-calls-reportSchemaError-twice-tp43121p43140.html
Sent from the Xerces - J - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscr...@xerces.apache.org
For additional commands, e-mail: j-dev-h...@xerces.apache.org

Reply via email to