sample xml
<root>
<first>
<second><![CDATA[hello, world]]></second>
</first>
<root>
I'm using xstream(1.4.7), stax2-api(3.1.4), woodstox(5.0.3).
@Test
public void xmlInputFactoryTest() throws XMLStreamException, IOException {
ClassPathResource resource = new ClassPathResource("/sample/input.xml");
NameCoder nameCoder = new XmlFriendlyNameCoder();
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLEventReader reader = factory.createXMLEventReader(resource.getInputStream());
XMLStreamReader streamReader = StaxUtils.createEventStreamReader(reader);
HierarchicalStreamReader hsr = new StaxReader(new QNameMap(), streamReader, nameCoder);
write(hsr);
}
public void write(HierarchicalStreamReader hsr) {
System.out.println(hsr.getNodeName() + ", " + hsr.getValue()); // should be print "hello,world" in second tag
if (hsr.hasMoreChildren()) {
hsr.moveDown();
write(hsr);
}
}
here is my sample test code
I can not get cdata string result in path "root/first/second"
I think XMLInputFactory.newInstance() return class affect to result.
when I add
factory.setProperty(XMLInputFactory.IS_COALESCING, true);
this code after get XMLInputFactory.newInstance().
It works. but it does not seem to be the answer.
.
Is not version compatible?
Is there any other way possible?