2011-08-05 24 views
4

我有一個看起來像這樣的元素。如何使用外部綁定文件覆蓋JAXB中的默認名稱?

<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> 

這是爲此元素創建的默認代碼。

@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; 

我的問題是什麼我需要把我的.xjb綁定文件改變從navmapOrKeymapOrContainer默認生成的名稱到別的東西像children

回答

4

例子:

<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> 

在你的綁定文件適應這一點,它會做。請參閱here以供參考。

清單11告訴祕訣:

<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> 
+0

我不能修改他們來自一個供應商的'.xsd'文件,我沒有在他們的控制,我不希望有合併當我重新生成綁定時,每次改變它們的結尾時都會發生更改。 –

+0

這就是我複製清單11的原因。此代碼段位於your.binding文件中。 –