如何使用外部绑定文件覆盖JAXB中的默认名称? [英] How to override the default name for in JAXB using a external binding file?

查看:91
本文介绍了如何使用外部绑定文件覆盖JAXB中的默认名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的元素。

I have an element that looks something like this.

 <xsd:element name="container">
    <xsd:complexType>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:element ref="navmap"/>
        <xsd:element ref="keymap" />
        <xsd:element ref="container" />
        <xsd:element ref="ad" />
        <xsd:element ref="button" />
        <xsd:element ref="checkbox" />        
      </xsd:choice>
    </xsd:complexType>
  </xsd:element>

以下是为此元素创建的默认代码。

Here is the default code that gets created for this element.

@XmlElements({
    @XmlElement(name = "navmap", type = Navmap.class),
    @XmlElement(name = "keymap", type = Keymap.class),
    @XmlElement(name = "container", type = Container.class),
    @XmlElement(name = "ad", type = Ad.class),
    @XmlElement(name = "button", type = Button.class),
    @XmlElement(name = "checkbox", type = Checkbox.class),
})
protected List<Object> navmapOrKeymapOrContainer;

我的问题是我需要在 <$ c中添加什么$ c> .xjb 绑定文件,用于将默认生成的名称从 navmapOrKeymapOrContainer 更改为 儿童

My question is What do I need to put in my .xjb bindings file to change the default generated name from navmapOrKeymapOrContainer to something else like children?

推荐答案

示例:

<xs:complexType>
  <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:annotation>
      <xs:appinfo>
        <jaxb:property name="Shapes"/>
      </xs:appinfo>
    </xs:annotation>
    <xs:element name="Rectangle" type="Rectangle"/>
    <xs:element name="Square" type="Square"/>
    <xs:element name="Circle" type="Circle"/>
  </xs:choice>
</xs:complexType>

在您的绑定文件中对此进行调整即可。请参阅此处以供参考。

Adapt this in your binding file and it will do. See here for reference.

清单11说明了这个秘密:

Listing 11 tells the secret:

<jxb:bindings version="1.0" 
  xmlns:jxb="http://java.sun.com/xml/ns/jaxb" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
  jxb:extensionBindingPrefixes="xjc">
<jxb:bindings schemaLocation="po4.xsd" node="/xs:schema">
  <jxb:globalBindings>
    <xjc:superClass name="com.syh.
    <xjc:serializable uid="12343"/>
  </jxb:globalBindings>
  <jxb:bindings node="//xs:element[@name='Widgets']//xs:complexType//xs:choice">
      <jxb:property name="Shapes"/>
  </jxb:bindings>
</jxb:bindings>

这篇关于如何使用外部绑定文件覆盖JAXB中的默认名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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