不能在单个 xsd 元素上使用 jaxb 绑定



我正在使用jaxb从XSD文件生成Java源代码。

我希望能够以每个元素的基础来指定源的生成源,但是每当我生成源时,我都会收到以下错误:

[ERROR] ****/src/main/xjb/common.xjb[8,24]
com.sun.istack.SAXParseException2: compiler was unable to honor this schemaBinding customization. It is attached to a wrong place, or its inconsistent with other bindings.

我的bindings file common.xjb正在尝试将元素(属性值)放置在软件包'com.myxml.common.api'中的元素:

<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings schemaLocation="../xsd/common/common.xsd" node="/xs:schema">
        <jxb:bindings node="//xs:element[@name='api']">
            <jxb:schemaBindings>
                <jxb:package name="com.myxml.common.api" />
            </jxb:schemaBindings>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

我的XSD文件common.xsd是:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.1" xml:lang="en">
    <xs:element name='api'>
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string" />
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
</xs:schema>

,我正在使用以下Maven插件来完成所有操作:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <id>schema00-generate</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>xjc</goal>
            </goals>
            <configuration>
                <schemaFiles>common/common.xsd</schemaFiles>
                <bindingFiles>common.xjb</bindingFiles>
                <bindingDirectory>${project.basedir}/src/main/xjb</bindingDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

为什么我会遇到此错误?如何解决?在此阶段,我没有任何其他绑定。

来自同一命名空间的元素无法映射到不同的软件包,因此除了顶级级别以外的任何内容

无法定义软件包

最新更新