Castor XML绑定和JAXB绑定有什么区别 [英] What is the difference between Castor XML binding and JAXB binding

查看:222
本文介绍了Castor XML绑定和JAXB绑定有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Castor XML和JAXB绑定之间有什么区别,因为它们都是将Java对象绑定到XML,反之亦然。

What is the difference between Castor XML and JAXB binding since both are binding java object to XML and vice versa.

更新:

使用Castor我可以这样做假设 packageA.ClassA packageB.ClassA 具有相同的属性和类名,只是它们位于不同的包中。

As using Castor I can do this Assume packageA.ClassA and packageB.ClassA have same attributes and class name just that they were located in different package.

packageA.ClassA - > XML -> packageB.ClassA 

如果我正在使用这个Marshall对象 packageA,则使用JAXB。 ClassA 到XML并从XML unmarshall到对象 packageB.ClassA 我有Casting错误。

By using JAXB if I am doing this Marshall object packageA.ClassA to XML and from XML unmarshall into object packageB.ClassA I got Casting error.

推荐答案

请注意,JAXB是一个API,并且有多个实现可用。

Please note that JAXB is an API, and there are multiple implementations available.

Sun提供了一个参考实现,并将其打包为J2EE(它也可以在J2SE 1.6中使用)。
Castor在JAXB从Sun出来之前诞生,并提供一些额外的功能。但是如果你想要的只是普通的XML绑定,那么参考Sun的实现应该会很好。

Sun provides a reference implementation and package it with J2EE (its available in J2SE 1.6 also). Castor was born before JAXB came out from Sun, and offers some extra features. But if all you want is plain XML binding, then the reference Sun implementation should work great.

有一个很棒的文章。有点旧,但大多数想法解释仍然有效。而且你不会发现文章提到JAXB注释,这使得现在更容易。

There is a great article in JavaWorld on this. A bit old but most ideas explained there still holds good. And you wont find the article mentioning JAXB annotations, which have made things easier nowadays.

Simple是一个易于使用的绑定框架,只需最少的简单配置。

Simple is an easy to use binding framework, and works with minimal 'simple' configuration.

DOM是一个不同的概念 - 它全部是关于解析而不是关于绑定。使用DOM解析器,您可以从XML中提取数据。但它没有给你一个对象映射工具。因此,您仍然必须使用DOM提取数据,然后编写代码将此数据推送到java对象。

DOM is an entrirely different concept - its all about parsing and does nothing about binding. Using a DOM parser, you can pull out data from XML. But it doesn't give you an object mapping facility. So you still have to pull the data using DOM, and then write code to push this data to a java object.

这篇关于Castor XML绑定和JAXB绑定有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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