English 中文(简体)
将大型XML档案(100k记录)输入数据库
原标题:Importing big XML file (100k of records) into database
  • 时间:2011-09-02 18:45:12
  •  标签:
  • java
  • xml
  • dom

I am facing the problem the problem while parsing the XML. Its cosuming 47% of CPU and its very slow. It seems like DOM loads the XML into the memory and from there it starts reading the XML Tree node by node.

I am reading a node and dumping it to the Database.

I want a solution where I can read the XML without loading into the memory.

我正在使用JDK1.4.2_05。

最佳回答

Look for SAX parser, it s only way to do something with XML without build of full DOM in memory. There are some limitations but maybe it will suit your needs.

问题回答

Nux StreamingPathFilter。 有了这个班子,你就能够把集水器的流放设施和低记忆足迹与轻度使用多功能二者结合起来。

但是,只有你的XML文件具有类似结构的记录,才能做到这一点。 例如,<代码>< person/>s。

(Following examples are taken from the Nux website and modified by me)

首先,请说明如何处理一份记录:

StreamingTransform myTransform = new StreamingTransform() {
  public Nodes transform(Element person) {
    // Process person element, i.e. store it in a database
    return new Nodes(); // mark element as subject to garbage collection
  }
}; 

接着,你创建了一个<代码>StreamingPathFilter,通过一个与你记录节点相符的XPath表述。

// parse document with a filtering Builder
NodeFactory factory = new StreamingPathFilter("/persons/person", null).
                            createNodeFactory(null, myTransform);
new Builder(factory).build(new File("/tmp/persons.xml"));

努克斯图书馆似乎不再保留。 但它仍然有用。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签