如何使用xquery在java中处理非常大的xml文件,如150mb [英] How to use xquery to process very large xml file like 150mb in java

查看:151
本文介绍了如何使用xquery在java中处理非常大的xml文件,如150mb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xquery来查询大型xml文档。使用xquery doc函数不会导致内存堆出站?
如何在java中使用xquery来查询大型xml文件。
示例说明将是appriciated。

I am using xquery to query a large xml document. Using xquery doc function will not cause memory heap outbound? How to use xquery in java to query a large xml file. Explanation with example will be appriciated .

推荐答案

首先,考虑到今天的强大程度,150 MB并不是那么大机器是。如果它增长到GB,则考虑使用Stax或SAX。

First of all 150 MB is not that huge, considering how powerful today's machines are. If it grows to GBs consider Stax or SAX instead.

XPath / Xquery资源使用将取决于实现,例如,在Dom4J的情况下,比较对于DOM ,XPath / Xquery通常显着减少了资源,但这通常取决于各种其他因素,如文档长度(即您拥有多少'childNode'元素)以及数据文档中的位置您感兴趣的地方。

XPath/Xquery resource usage will be dependent on the implementation, For Example, in case of Dom4J, Comparing to DOM, XPath/Xquery is often significantly less resource heavy, but this often depends on various other factors like length of the document (i.e. how many 'childNode' elements you have) and the location in the document of the data in which you are interested.

从这里引用 https:// stackoverflow。 com / a / 725007/6785908


XPath内存使用和完成时间往往会进一步增加
记录你去。例如,假设您有一个带有20,000个childNode元素的XML
文档,每个childNode都有一个您事先知道的唯一
标识符,并且您想要从文档中提取已知的
childNode 。提取第18,345个childNode将
使用比提取第3个更多,更多,更多的内存。

XPath memory usage and completion time tends to increase the further down the document you go. For example, let's say you have an XML document with 20,000 childNode elements, each childNode has a unique identifier that you know in advance, and you want to extract a known childNode from the document. Extracting the 18,345th childNode would use much, much, much more memory than extracting the 3rd.

因此,如果您使用XPath提取所有childNode元素,你可能
发现它比解析成DOM效率低。 XPath通常是一种
简单的方法来提取XML doucment的一部分。我不建议用
来处理所有的XML文档。

So if you are using XPath to extract all childNode elements, you may find it less efficient than parsing into a DOM. XPath is generally an easy way of extracting a portion of an XML doucment. I'd not recommend using it for processing all of an XML document.



Spring Xquery例子



https: //github.com/spring-projects/spring-integration-extensions/tree/master/samples/xquery

这是我从第一次谷歌搜索结果得到的 https://docs.oracle.com/database/121/ADXDK/adx_j_xqj.htm#ADXDK115

This is what I got from first google search result https://docs.oracle.com/database/121/ADXDK/adx_j_xqj.htm#ADXDK115

import javax.xml.xquery.XQConnection;
import javax.xml.xquery.XQException;
import javax.xml.xquery.XQPreparedExpression;
import javax.xml.xquery.XQSequence;

import oracle.xml.xquery.OXQDataSource;

public class HelloWorld {

    public static void main(String[] args) throws XQException {
        OXQDataSource ds = new OXQDataSource();
        XQConnection con = ds.getConnection();
        String query = "<hello-world>{1 + 1}</hello-world>";
        XQPreparedExpression expr = con.prepareExpression(query);
        XQSequence result = expr.executeQuery();

        // prints "<hello-world>2</hello-world>"
        System.out.println(result.getSequenceAsString(null));

        result.close();
        expr.close();
        con.close();
    }

} 

我想重申一下,因为一个150 MB大小的xml处理,你不必过分担心内存占用。

I want to reiterate that, for a 150 MB sized xml processing, you shouldn't worry too much about the memory footprint.

这篇关于如何使用xquery在java中处理非常大的xml文件,如150mb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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