Woodstox : Exploring Validation Errors Using ValidationProblem

Overview

In this article, we shall demonstrate how details of validation error can be obtained by using
ValidationProblem
class.

Create the employee.dtd as shown below.

It defines the employee element that contains id, name and salary sub-elements.

Create invalidEmployee.xml as shown below. Note that it is
not
in accordance with employee.dtd described above as it defines the ‘title’ element (see line 4 below) instead of ‘salary’ element.

Create TestValidationProblem class as shown below.

Catch
XMLValidationException
(see lines 36-46 below).

When validation related exception is thrown, explore the details extracting
ValidationProblem
from the exception (see line 37 below).

The detailed error message and its Location can be further extracted from
ValidationProblem
(see lines 38-39 below).

The output of the program demonstrating the usage of
ValidationProblem
is shown below:

Download Source Code for this Program

Leave a Comment