Parsing xml with StAX: not getting a large content tag

匆匆过客 提交于 2020-01-17 15:25:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!