I have taken over the maintenance of an application that uses a stax parser to break down an XML file of many records into individual records for further processing. Using this type of parser for this purpose is overkill in my opinion but I didn't write it.
The application is now encountering data such as this:
<name><![CDATA[A & B]]></name>
Our current parser returns an event for the begin 'name' tag. The next event is a character event with the value 'A & B'.
From Sun's web page I found this:
Reporting CDATA Events The javax.xml.stream.XMLStreamReader implemented in the Streaming XML Parser does not report CDATA events. If you have an application that needs to receive such events, configure the XMLInputFactory to set the following implementation-specific report-cdata-event property:
XMLInputFactory factory = XMLInptuFactory.newInstance();
factory.setProperty("report-cdata-event", Boolean.TRUE);
The parser we are using does not support the 'report-cdata-event' property.
I want to find a parser that will report such an event so I don't have to check every single piece of text for characters that need to be guarded by the CDATA construct.
UPDATE:
After posting this I browsed some of the related questions and there was mention of the 'isCoalescing' property; for the record it is being set to FALSE.
The correct property is: "http://java.sun.com/xml/stream/properties/report-cdata-event". The property XMLInputFactory.IS_COALESCING must be set to false (default setting).
If these conditions are met, it works fine (tested with Oracle Java 7u51).
Pretty sure Woodstox should handle that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With