使用StAX和XPath读取大量XML文件 [英] Reading Huge XML File using StAX and XPath

查看:111
本文介绍了使用StAX和XPath读取大量XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入文件包含数千个XML格式的事务,大小约为10GB。要求是根据用户输入选择每个事务XML并将其发送到处理系统。

The input file contains thousands of transactions in XML format which is around 10GB of size. The requirement is to pick each transaction XML based on the user input and send it to processing system.

文件的示例内容

<transactions>
    <txn id="1">
      <name> product 1</name>
      <price>29.99</price>
    </txn>

    <txn id="2">
      <name> product 2</name>
      <price>59.59</price>
    </txn>
</transactions>

(技术)用户应该给出输入标签名称,如< ; TXN>

The (technical)user is expected to give the input tag name like <txn>.

我们希望提供更通用的解决方案。文件内容可能不同,用户可以提供类似 // transactions / txn 的XPath表达式来选择单个交易。

We would like to provide this solution to be more generic. The file content might be different and users can give a XPath expression like "//transactions/txn" to pick individual transactions.

我们需要考虑的技术问题很少


  • 该文件可以共享位置或FTP

  • 由于文件很大,我们无法在JVM中加载整个文件

我们可以在这种情况下使用StAX解析器吗?它必须将XPath表达式作为输入和选择/选择事务XML。

寻找建议。在此先感谢。

Looking for suggestions. Thanks in advance.

推荐答案

Stax和xpath是截然不同的事情。 Stax允许您仅向前解析流式XML文档。 Xpath允许在两个方向上进行解析。 Stax是一个非常快速的流式XML解析器,但是,如果你想要xpath,java就有一个单独的库。

Stax and xpath are very different things. Stax allows you to parse a streaming XML document in a forward direction only. Xpath allows parsing in both directions. Stax is a very fast streaming XML parser, but, if you want xpath, java has a separate library for that.

看看这个问题进行非常类似的讨论: SAX模型是否有任何XPath处理器?

Take a look at this question for a very similar discussion: Is there any XPath processor for SAX model?

这篇关于使用StAX和XPath读取大量XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆