[英]java xml parsing a large file and db relation
I have a 10+ MB xml file with consists of node(about 10K to 20K) with relations. 我有一个10+ MB的xml文件,包含有关系的节点(大约10K到20K)。
<.....>
<Emplyoyee>
<name>Jack</name>
<age>35</age>
<supervisor></supervisor>
<....>
</Emplyoyee>
<.....>
<.....>
<.....>
<Emplyoyee>
<name>Smith</name>
<age>20</age>
<supervisor>Jack</supervisor>
<....>
</Emplyoyee>
<.....>
Now, I want to parse this file and store all the details in DB with "Employee" table which has a field(ID) called "supervisorID". 现在,我想解析这个文件并将所有细节存储在DB中,其中“Employee”表有一个名为“supervisorID”的字段(ID)。 Until now I have tried to make a List of all the employees and then iterating the List for finding supervisor relation.
到目前为止,我已尝试制作所有员工的列表,然后迭代列表以查找主管关系。
Please suggest me a memory efficient and faster way to do this. 请建议我一个有效的内存和更快的方法来做到这一点。 What libraries can I use to handle this type of problems.
我可以使用哪些库来处理此类问题。
You can convert data from XML
file to Java Objects using JAXB
and insert Java objects to database using Hibernate
+ JPA
. 您可以使用
JAXB
将数据从XML
文件转换为Java对象,并使用Hibernate
+ JPA
将Java对象插入数据库。
You can create 2 DTO 您可以创建2个DTO
Emplyoyee
- with all info about Emplyoyee (name, age, ...) Emplyoyee
- 关于Emplyoyee的所有信息(姓名,年龄,......)
and 和
Emplyoyees
with List<Emplyoyee>
for JAXB unmarshalling Emplyoyees
与List<Emplyoyee>
为JAXB数据编
EDIT: WITHOUT JAXB and JPA 编辑:没有JAXB和JPA
You can parse file using javascript and send SQL queries usinf Ajax 您可以使用javascript解析文件并使用Ajax发送SQL查询
var xmlDoc = new ActiveXObject("MSXML.DOMDocument");
xmlDoc.async = false;
xmlDoc.preserveWhiteSpace = true;
xmlDoc.load(pathToFile);
var nodes = xmlDoc.selectNodes("/Emplyoyee");
for (var node = nodes.nextNode(); node != null; node = nodes.nextNode())
{
// get another nodes, create SQL query and sent it to server usinj Ajax
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.