java 既然 XMLBeans 已经退役了,用什么来代替它?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27727546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:17:16  来源:igfitidea点击:

What to use instead of XMLBeans now that it has been retired?

javaxmlxsdxmlbeans

提问by John

I'm starting a new project where I have third party XSD. My Java application needs to generate XML messages that conform to this XSD and read incoming XML messages that conform to this XSD. In the past I have used Apache XMLBeans for this (http://xmlbeans.apache.org/). It looks like XMLBeans has been retired. What is a good replacement for XMLBeans now that it has been retired? I have used XStream on other projects but I don't recall that XStream has the ability to generate Java classes from an XSD so I'm thinking that it is not a good choice over XMLBeans for this use case. I have hundreds of types defined in the XSD and would really prefer not to have to create the hundreds of Java classes to represent them in Java by hand.

我正在开始一个拥有第三方 XSD 的新项目。我的 Java 应用程序需要生成符合此 XSD 的 XML 消息并读取符合此 XSD 的传入 XML 消息。过去,我为此使用了 Apache XMLBeans ( http://xmlbeans.apache.org/)。看起来 XMLBeans 已经被淘汰了。既然 XMLBeans 已经退役,它有什么好的替代品?我在其他项目中使用过 XStream,但我不记得 XStream 能够从 XSD 生成 Java 类,所以我认为对于这个用例,它不是 XMLBeans 的好选择。我在 XSD 中定义了数百种类型,并且真的不想创建数百个 Java 类来手动用 Java 表示它们。

In other words, using the XStream example given here: http://x-stream.github.io/tutorial.html, I have a Person type (and 99 others) defined in the XSD. Using XMLBeans I can generate the Java classes to represent these objects but using XStream I would need to create the Java classes (e.g. Person) by hand or using some other tool. What tool should I use in this case?

换句话说,使用此处给出的 XStream 示例:http: //x-stream.github.io/tutorial.html,我在 XSD 中定义了一个 Person 类型(以及其他 99 个)。使用 XMLBeans 我可以生成 Java 类来表示这些对象,但使用 XStream 我需要手动或使用其他工具创建 Java 类(例如 Person)。在这种情况下我应该使用什么工具?

Any help would be greatly appreciated.

任何帮助将不胜感激。

Thanks, John

谢谢,约翰

采纳答案by Steve

Have you looked at JAXB? I haven't done anything with either of these, but googling for "alternative to XMLBeans" brings up lots of references to this package. Here's an article that compares them...

你看过JAXB吗?我没有对其中任何一个做过任何事情,但是在谷歌上搜索“XMLBeans 的替代品”会带来很多对该包的引用。这是一篇比较它们的文章......

http://blog.bdoughan.com/2012/01/how-does-jaxb-compare-to-xmlbeans.html

http://blog.bdoughan.com/2012/01/how-does-jaxb-compare-to-xmlbeans.html