Woodstox : Handling Warning Using XMLReporter

Overview

This article demonstrates the usage of
XMLReporter
in handling warning during StAX parsing.

Create employee.dtd as shown below.

Note that the entity ‘commonAddress’ is defined twice in the DTD (see lines 5-6 below).

This will throw a warning condition during parsing.

Create employee.xml as shown below.

Create TestWarning as shown below.

Define a custom schema factory called ‘MyDTDSchemaFactory’ (lines 61-78 below).

Implement
XMLReporter
and override the
report
method (see lines 80-90 below).

Instantiate ‘MyDTDSchemaFactory’ by passing ‘MyXMLReporter’ object (see line 27 below).

During parsing, a warning message shall be generated for duplicate entities in DTD and the message shall be passed via the callback method (see line 86 below).

The output of the program demonstrating handling of warning message is shown below.

Download Source Code for this Program

Leave a Comment