gpt4 book ai didi

java - 不能在单个 xsd 元素上使用 jaxb 绑定(bind)

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:20 27 4
gpt4 key购买 nike

我正在使用 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.

我的绑定(bind)文件 common.xjb 试图将名称(属性值)为“api”的元素放入包“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>

为什么会出现此错误,我该如何解决?据我所知,在此阶段我没有使用任何其他绑定(bind)。

最佳答案

来自同一命名空间的元素不能映射到不同的包,因此不能为顶级之外的任何其他内容定义包

关于java - 不能在单个 xsd 元素上使用 jaxb 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13068593/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com