0

I want to execute xslt transform and handle all errors, if possible. But this piece of code

        transformer = factory.newTransformer(xslt);

doesn't throws an exception, but prints following to console:

Неизвестный ИД системы; Номер строки 7; Номер столбца 40;        org.apache.xml.utils.WrappedRuntimeException: Переменная site_name не найдена

(in English this means Unknown ID system line number 7, column number 40;   org.apache.xml.utils.WrappedRuntimeException: site_name variable was not found) 

How can I force newTransformer throw an exception or collect these errors after function is done? Haven't found any valuable info on the net...

1 Answer 1

1

I'm not sure about throwing the exception, but you can collect them with an ErrorListener. Something along these lines:

class ErrorCollector implements ErrorListener {

    private List<TransformerException> errors = new ArrayList<TransformerException>();

    @Override
    public void error(TransformerException exception) throws TransformerException {
        errors.add(exception);
    }

    ...
}

(the code is not complete, but I think you get the picture)

Then add it to your factory:

ErrorCollector errorCollector = new ErrorCollector();
factory.setErrorListener(errorCollector);

And access to the errors in the collector after that.

Hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.