SAX XML Java Entities problem

旧城冷巷雨未停 提交于 2019-12-06 01:36:37
SanSentinel

characters() is not guaranteed to return of all the characters in a single call. From the Javadoc:

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks.

You need to append the characters returned in all of the calls, something like:

private StringBuffer tempValue = new StringBuffer();

startElement()
{
    tempValue.setLength(0); // clear buffer...
}

characters(characters(char[] ch, int start, int length)
{
    tempValue.append(ch, start, length); // append to buffer
}

endElement()
{
    String value = tempValue.toString(); // use characters in buffer...
}
  1. I don't think you can turn off entity resolution.

  2. The characters method can be called multiple times for a single tag, and you have to collect the characters across the multiple calls rather than expecting them all to arrive at once.

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