In this article, we shall demonstrate handling of exception when XML is not well formed.
Create employee.xml as shown below.
Note that this XML document is not well-formed e.g. the ‘salary’ end element is not properly closed (see line 4 below).
Create TestXmlException class.
is caught and error message is redirected to output console (see lines 36-39 below).
Woodstox shall throw the
when mal-formed employee.xml (defined above) is parsed.
The output of the program demonstrating that Woodstox throws an exception when parsing the mal-formed employee.xml is shown below.
Note that detailed message is provided by Woodstox (see lines 6-7 below).
Download Source Code for this Program