This article demonstrates how to optionally coalesce CData content using Aalto StAX parser.
This program shall parse the same XML document twice: once without coalescing and once with coalescing and display the output corresponding to each scenario.
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
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-25 below)