Java到XSD或XSD到Java [英] Java to XSD or XSD to Java

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

问题描述

我知道,使用JAXB,您可以从XSD生成Java文件,您还可以从带注释的POJO生成XSD 。各有哪些优缺点?一个整体比另一个好吗?

I know that, using JAXB, you can generate Java files from an XSD and that you can also generate the XSD from annotated POJOs. What are the advantages and disadvantages of each? Is one overall better than the other?

我们基本上想要将事件序列化为XML格式的日志。

We basically want to serialize events to a log in XML format.

推荐答案

最终取决于你想要关注的地方:

Ultimately it depends on where you want to focus:

如果XML Schema是最重要的事情

然后最好从XML模式开始并生成JAXB模型。有一个JAXB(JSR-222)实现无法生成的XML模式的详细信息:

Then it is best to start from the XML schema and generate a JAXB model. There are details of an XML schema that a JAXB (JSR-222) implementation just can't generate:


  • 除0以外的maxOccurs, 1,或无界

  • 简单类型上的多个方面

  • 模型组

如果对象模型是最重要的事情

如果您将使用Java模型而不仅仅是在对象和XML之间进行转换(即使用JPA进行持久化)然后我建议从Java对象开始。这将为您提供最大的控制权。

If you will be using the Java model for more than just converting between objects and XML (i.e. using it with JPA for persistence) then I would recommend starting with Java objects. This will give you the greatest control.

这篇关于Java到XSD或XSD到Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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