Java XML 绑定

Java XML Binding(Java XML 绑定)

本文介绍了Java XML 绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您使用什么将 XML 绑定到 Java?JAXB、Castor 和 XMLBeans 是一些可用的选择.我看到的比较都是三四年前的.我愿意接受其他建议.编组/解组的性能和易用性是特别重要的.

What are you using for binding XML to Java? JAXB, Castor, and XMLBeans are some of the available choices. The comparisons that I've seen are all three or four years old. I'm open to other suggestions. Marshalling / unmarshalling performance and ease of use are of particular interest.

澄清:我不仅想看看你使用什么框架,还想看看你使用其中一个框架而不是其他框架的理由.

Clarification: I'd like to see not just what framework you use, but your reasoning for using one over the others.

推荐答案

JiBX.以前我使用 Castor XML,但 JiBX 被证明要好得多,尤其是在性能方面(将某些应用程序代码从 Castor XML 直接移植到 JiBX 使其速度提高了 9 倍).我还发现 JiBX 的映射格式比 Castor 的更优雅.

JiBX. Previously I used Castor XML, but JiBX proved to be significantly better, particularly in terms of performance (a straight port of some application code from Castor XML to JiBX made it 9x faster). I also found the mapping format for JiBX to be more elegant than Castor's.

JiBX 通过使用编译后字节码操作而不是 Castor 采用的反射方法来实现其性能.这样做的好处是它对编写映射类的方式要求较少.不需要 getter、setter 和无参数构造函数来满足这些工具.大多数情况下,您可以在不考虑映射问题的情况下编写类,然后不加修改地对其进行映射.

JiBX achieves its performance by using post-compilation bytecode manipulation rather than the reflection approach adopted by Castor. This has the advantage that it places fewer demands on the way that you write your mapped classes. There is no need for getters, setters and no-arg constructors just to satisfy the tools. Most of the time you can write the class without considering mapping issues and then map it without modifications.

这篇关于Java XML 绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Java XML 绑定