问题
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