我有一个大的xml文件(1Gb).我需要对这个xml文件进行很多查询(例如使用xpath).结果是xml的一小部分.我希望查询尽可能快,但1Gb文件可能对工作内存来说太大了.
xml看起来像这样:
<all>
<record>
<id>1</id>
... lots of fields. (Very different fields per record including (sometimes) subrecords
so mapping on a relational database would be hard).
</record>
<record>
<id>2</id>
... lots of fields.
</record>
.. lots and lots and lots of records
</all>
Run Code Online (Sandbox Code Playgroud)
我需要随机访问,例如使用键作为键选择记录.(Id是最重要的,但其他字段也可以用作键).我事先不知道查询,它们到达并且必须尽快执行,没有批量执行但是实时.SAX看起来不太有希望,因为我不想为每个查询重读整个文件.但DOM看起来也不是很有希望,因为文件非常大并且增加额外的结构开销几乎肯定意味着它不适合工作内存.
我可以使用哪种java库/方法来处理这个问题?