I use woodstox to read xml file but i have a problem the library not notify me when the element read is CDATA. Someone can help me? This is my code and i want to understand where is the error.
XMLInputFactory2 factory = new WstxInputFactory();
if (factory.isPropertySupported(XMLInputFactory2.P_REPORT_CDATA)) {
factory.setProperty(XMLInputFactory2.P_REPORT_CDATA, Boolean.TRUE);
}
FileReader toRead = new FileReader(source);
XMLStreamReader2 streamReader =XMLStreamReader2)factory.createXMLStreamReader(toRead);
while (streamReader.hasNext()) {
if (streamReader.getEventType() == XMLStreamReader.CDATA) {
System.out.println("<![CDATA[" + streamReader.getText() + "]]>");
}
}
Your code is buggy. I will actually let you figure out how, as this is really pretty basic issue with using Stax API. Hint: try actually printing out event type, see if you can find something interesting.