如何从XSD生成实现可序列化的类? [英] How to generate classes from XSD that implements serializable?

查看:345
本文介绍了如何从XSD生成实现可序列化的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从一个包(.jar)中的XML架构(XSD)生成许多类。
如何将这些类配置为可序列化?

I need to generate many classes from my XML Schema (XSD) in a package (.jar). How can I configure these classes to be serializable?

(我使用的是Eclipse和JAX-B)

(I'm using Eclipse and JAX-B)

推荐答案

如果您使用XJC,建议您阅读以下参考资料:用于XML绑定的JavaTM架构:JAXB RI供应商扩展定制

If you are using XJC, I recomend you to read this reference: JavaTM Architecture for XML Binding: JAXB RI Vendor Extensions Customizations :

您必须添加您的模式接口命名空间定义以添加xjc aditional标记:

You have to add in your schema aditional namespaces definition to add xjc aditional markup:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
           jaxb:extensionBindingPrefixes="xjc"
           jaxb:version="1.0">

然后,包括一个< xjc:serializable> 节点< jaxb:globalBindings>

<xs:annotation>
   <xs:appinfo>
      <jaxb:globalBindings generateIsSetMethod="true">
          <xjc:serializable uid="12343"/>
      </jaxb:globalBindings>
   </xs:appinfo>
</xs:annotation>

这将导致所有具体的类实现Serializable接口。此外,您可以定义生成的类的UUID值(这是可选属性)。

This will cause that all the concrete classes implement the Serializable interface. Also, you can define the UUID value of the resulting classes (that's an optional attribute).

这篇关于如何从XSD生成实现可序列化的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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