Overview
This article demonstrates how to optionally coalesce CData content using Woodstox StAX parser.
This program shall parse the same XML document twice: once without coalescing and once with coalescing.
Create employee.xml as shown below.
Note that the name of the employee is mentioned within a CDATA section (see lines 4-6 below).
Create TestCoalesceCData as shown below.
In particular, note the
XMLInputFactory.IS_COALESCING
property that is set using a boolean flag ‘coalesce’ (see line 19 below).
In the main method, first we execute the program without coalescing and then with coalescing (see lines 41-47 below).
The output of the program demonstrating CDATA coalescing is shown below:
- Parse without coalescing CDATA (see lines 1-11 below)
- Parse with coalescing CDATA (see lines 13-23 below)