替代使用JRXmlUtils.parse()来解析巨大的XML文件?

时间:2016-04-18 16:36:37

标签: java xml xml-parsing jasper-reports

我正在开发一个应用程序,我必须使用以下结构解析一个巨大的XML文件(65 MB),以便使用Jasper Reports从中生成PDF文件:

<A>
    <a attribute1="" attribute2="" attribute3=""/>
</A>
<B>
    <b attribute1="" attribute2="" attribute3=""/>
</B>

<C>
    <c attribute1="" attribute2="" attribute3=""/>
</C>
<D>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    <d attribute1="" attribute2="" attribute3=""/>
    ...
</D>

...有大量的<d>标签(最少50万个标签)。

我的问题是这些标签非常庞大,导致java.lang.OutOfMemoryError: Java heap space错误。

我使用此行解析文件:

Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(xmlPath));

有没有人可以使用JRXmlUtils.parse方法?为了能够避免OutOfMemoryError错误(不增加堆空间)?

谢谢

编辑:

我已经看过this关于SAXParser的帖子,但我不知道如何根据我的情况调整它,因为我的XML结构有点特殊(我有很多数据)在我有问题的标签之前)...有任何澄清吗?

0 个答案:

没有答案
相关问题