简体   繁体   English

如何增加EntityExpansionLimit以使用SAX解析XML文件

[英]How to increase entityExpansionLimit for parsing XML files using SAX

I am trying to parse an XML file which is 1.23 GB using SAX parser in Java. 我正在尝试使用Java中的SAX解析器来解析一个1.23 GB的XML文件。 I am using Mac OS and JDK 1.7.0.51. 我正在使用Mac OS和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. 您的帮助将不胜感激。

I found a solution for this issue. 我找到了解决此问题的方法。 It is working with me at the moment. 目前正在与我合作。 I am using Eclipse. 我正在使用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. 希望这对可能遇到此问题的人有所帮助。

That's discussed in https://jaxp.java.net/1.4/JAXP-Compatibility.html , among other places. 在其他地方,我们已经在https://jaxp.java.net/1.4/JAXP-Compatibility.html中进行了讨论。 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. 如果FEATURE_SECURE_PROCESSING是活动的(默认情况下可能是活动的),则需要将其关闭,然后将解析器属性http://apache.org/xml/properties/entity-expansion-limit设置为所需的大小。

Note that security concern, though. 但是请注意安全性。 In general anything which is doing that much entity expansion has to be treated as a possible DOS attack. 通常,任何进行大量实体扩展的操作都必须视为可能的DOS攻击。 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. 不可否认,> 1GB的文件是一种特殊情况。 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. 坦率地说,您可能要考虑该文档是否应该像看起来那样使用实体,以及是否有更好的方法来表达其需要说的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM