如何在xsdtojava自动生成的jaxb元素上添加接口?

如何在xsdtojava自动生成的jaxb元素上添加接口?,java,xml,jaxb,xjc,Java,Xml,Jaxb,Xjc,我想为由jaxb和xsdtojava自动生成的类添加一个超级接口 问题:我只能在根元素上添加接口(我不想要,但只是为了测试目的) 我要应用继承的元素是liselement xsd我无法控制 <xs:schema> <xs:element name="myRequest"> <xs:complexType> <xs:sequence> <xs:element nam

我想为由
jaxb
xsdtojava
自动生成的类添加一个超级
接口

问题:我只能在根元素上添加接口(我不想要,但只是为了测试目的)

我要应用继承的元素是
liselement

xsd
我无法控制

<xs:schema>
    <xs:element name="myRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="thelist">
                   <xs:complexType>
                      <xs:sequence>
                         <xs:element name="thelistelement" maxOccurs="unbounded">
                    ...

...
绑定文件:

<jaxb:bindings    
    xmlns:jaxb="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"
    xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
    jaxb:extensionBindingPrefixes="xjc inheritance"
    jaxb:version="2.1">

    <!-- this works -->
    <jaxb:bindings schemaLocation="xsd/my.xsd">
        <jaxb:bindings node="//xs:element[@name='myRequest']">
                    <inheritance:implements>MyInterface</inheritance:implements>
        </jaxb:bindings>
    </jaxb:bindings>

    <!-- this does NOT work -->
    <jaxb:bindings schemaLocation="xsd/my.xsd">
        <jaxb:bindings node="//xs:element[@name='thelistelement']">
                    <inheritance:implements>MyInterface</inheritance:implements>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

MyInterface
MyInterface
使用
-Xinheritance
运行

输出应为:

...
List<Thelistelement> thelist;

class Thelistelement implements MyInterface {

}
。。。
列出清单;
类ListElement实现MyInterface{
}

但是list元素类上缺少接口。那么为什么它在根元素
myRequest
上工作呢

我必须向节点添加一个
/xs:complexType
。但我不知道为什么会这样

注意complexType前的单斜杠很重要

<jaxb:bindings schemaLocation="xsd/my.xsd">
    <jaxb:bindings node="//xs:element[@name='thelistelement']/xs:complexType">
                <inheritance:implements>MyInterface</inheritance:implements>
    </jaxb:bindings>
</jaxb:bindings>

MyInterface