简体   繁体   English

哪个xml parse暗示仅解析XML的一部分并将其存储在DB中

[英]Which xml parse impl to parse only a part of the XML and store it in DB

I've been searching the web but I didn't find anything that meet my requirements and am not sure what to do. 我一直在网上搜索,但是找不到符合我要求的内容,也不知道该怎么办。 I know this has been asked several times but not exactly the same as this. 我知道这个问题已经被问过几次了,但并不完全一样。

We have some large XML files (still don't know size but I guess surely less than 1GB). 我们有一些大的XML文件(仍然不知道大小,但我想肯定小于1GB)。 We only need a part of this files (only a part of the XSD is useful for us), that we must read and then store in DB. 我们只需要一部分文件(只有一部分XSD对我们有用),我们必须先阅读然后将其存储在DB中。 In the future we'll probably need to recreate XML files, but this is not covered in this first phase. 将来,我们可能需要重新创建XML文件,但这在第一阶段中没有涉及。

Well, I've already seen that for something like this is better to use JAXB, but I'm a bit confused with JAXB implementations. 好了,我已经看到对于像这样的东西,使用JAXB更好,但是我对JAXB实现有些困惑。 We have JDK implementation, and Castor, and Metro, and EclipseLink Moxy, and I think I've seen at least 2 more implementations. 我们有JDK实现,Castor,Metro和EclipseLink Moxy,我想我至少看到了另外两个实现。 Wich one would be the best to bind this XML to POJO classes and then to persist to DB with JPA? 用这种方式将XML绑定到POJO类,然后再使用JPA持久化到数据库是最好的方法吗? Is there a better implementation than the ones I've listed? 是否有比我列出的方案更好的实施方案? Any of the ones I've listed is out-of-date? 我列出的任何一个都过时了吗? (I ask this because many pages I've been visiting are quite old and am not sure if there has been changes in the past years) (我之所以这样问,是因为我访问过的许多页面都已经很旧,并且不确定过去几年是否有所变化)

Performance is important, of course, but the important thing is that we only need part of the elements included in the XML. 性能固然重要,但是重要的是我们只需要XML中包含的部分元素。 BTW, this is for use with SG1-XML standard. 顺便说一句,这是与SG1-XML标准一起使用的。

Thanks in advance. 提前致谢。

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group. 注意:我是EclipseLink JAXB(MOXy)的负责人,并且是JAXB(JSR-222)专家组的成员。

JAXB (JSR-222) is the Java standard for XML binding it is leveraged by other standards such as JAX-WS (SOAP Web Services) and JAX-RS (RESTful Web Services). JAXB(JSR-222)是用于XML绑定的Java标准,它被其他标准(例如JAX-WS(SOAP Web服务)和JAX-RS(RESTful Web服务))利用。

  • Project JAXB (part of Metro) is the reference implementation, and the version of the JAXB included in most implementationjs of the JDK/JRE is derived from it. 项目JAXB (Metro的一部分)是参考实现,大多数JDK / JRE实现js中都包含的JAXB版本是从其派生的。
  • EclipseLink MOXy is a JAXB compliant implementation passing all the necessary compliance tests. EclipseLink MOXy是符合JAXB的实现,通过了所有必要的符合性测试。 It offers useful extensions such as path based mapping and additional support for mapping JPA entities (EclipseLink also provides a JPA implementation). 它提供了有用的扩展,例如基于路径的映射以及对映射JPA实体的附加支持(EclipseLink还提供了JPA实现)。
  • Castor - Castor appears to offer atleast a partial JAXB implementation (see: http://docs.codehaus.org/display/CASTOR/Castor+JAXB ). Castor -Castor似乎至少提供了部分JAXB实现(请参阅: http : //docs.codehaus.org/display/CASTOR/Castor+JAXB )。 In general I would recommend staying away from anything that only implements part of a specification. 通常,我建议不要使用仅实现部分规范的内容。

Since the document is large and you only need a portion of it, I would recommend using a JAXB implementation in combination with a StAX parser. 由于文档很大,您只需要其中的一部分,因此我建议结合使用JAXB实现和StAX解析器。 You can use an XMLStreamReader to advance to the portion of the document you wish to unmarshal, and only unmarshal the chunk you need. 您可以使用XMLStreamReader前进到要解组的文档部分,而仅解组所需的块。


Which one would be the best to bind this XML to POJO classes and then to persist to DB with JPA? 将XML绑定到POJO类,然后再通过JPA持久化到数据库,哪一种是最好的?

As MOXy is a component of EclipseLink which is the JPA reference implementation we spend a significant amount of effort on those use cases. 由于MOXy是EclipseLink(它是JPA参考实现)的组件,因此我们在这些用例上花费了大量的精力。 I'm the MOXy lead and I share a cubicle wall with Mike Keith the former JPA co-spec lead. 我是MOXy主管,我与前JPA共同规格主管Mike Keith共享一个隔间墙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM