问题
I am using StAX to parse my xml file, the problem is that when the tag content is large, StAX is not able to give me the whole content. Here is a part of my xml doc, the content of payload tag is so much more larger, can't print it all in SOF:
<payload>{\"id\": \"ENTITY24\",\"attr1\": {\"type\": \"sensor\",\"type\": \"type1\",\"value\": \"val1\",\"metadata\": {}}}</payload>
Here is a part of my code parsing it:
if(startElement.getName().getLocalPart().equals("payload")){
xmlEvent = xmlEventReader.nextEvent();
if(xmlEvent.isCharacters()){
setPayload(xmlEvent.asCharacters().getData());
}
}
Any idea why StAX is not able to give the whole tag content? Thanks and best regards.
回答1:
You should either concatenate all isCharacters
events between other events or set the IS_COALESCING property.
Just like with SAX, STAX may offer you one single run of characters as multiple events.
来源:https://stackoverflow.com/questions/38631293/parsing-xml-with-stax-not-getting-a-large-content-tag