我使用woodstox 来读取xml 文件,但是当读取的元素是CDATA 时,库没有通知我。有人可以帮助我吗?这是我的代码,我想了解错误在哪里。
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() + "]]>");
}
}