How to increase entityExpansionLimit for parsing XML files using SAX

蓝咒 提交于 2021-02-10 13:15:14

问题


I am trying to parse an XML file which is 1.23 GB using SAX parser in Java. I am using Mac OS and JDK 1.7.0.51. Unfortunately, I am getting the following error:

The pasrser has encountered more than "64000" entity expansions in this document; this is the limit imposed by the JDK.

I have been recommended to get the entity expansion extended but do not know how to do this. Could anyone please help me in this issue. Your help would be very much appreciated.


回答1:


I found a solution for this issue. It is working with me at the moment. I am using Eclipse. Here are the steps:

1- Right-click on the project in Eclipse
2- Select Run -> Run Configurations
3- Select Arguments 
4- In the VM arguments, add the following:  -DentityExpansionLimit=2500000

Hope this helps people who may encounter this issue.




回答2:


That's discussed in https://jaxp.java.net/1.4/JAXP-Compatibility.html, among other places. You'd need to turn off FEATURE_SECURE_PROCESSING if it's active (probably is, by default), and set the parser property http://apache.org/xml/properties/entity-expansion-limit to the desired size.

Note that security concern, though. In general anything which is doing that much entity expansion has to be treated as a possible DOS attack. Which is why this limit exists, and in fact is often set lower rather than higher in realworld systems.

Admittedly a >1GB document is a special case. But I'd recommend you relax the limit only for the task which is processing that specific document. And frankly, you might want to consider whether that document should be using entities as much as it apparently does, and whether there's a better way for it to say what it needs to say.



来源:https://stackoverflow.com/questions/21588619/how-to-increase-entityexpansionlimit-for-parsing-xml-files-using-sax

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