首页 > 解决方案 > 为 xjc 优化外部绑定 XML

问题描述

您好我正在尝试为 xjc 创建一个外部绑定 XML,但出现 2 个错误:

[ERROR] A class/interface with the same name "x.x.DaysOfWeek" is already in use. Use a class customization to resolve this conflict. [ERROR] (Relevant to above error) another "DaysOfWeek" is generated from here.

我错过了什么重要的东西吗?我需要第二双眼睛。谢谢

<!-- data.xsd -->
<xs:complexType name="DaysOfWeek">
  <xs:sequence>
    <xs:element ref="DaysOfWeek"/>
  </xs:sequence>
</xs:complexType>

<xs:element name="DaysOfWeek">
  <xs:complexType mixed="true">
    <xs:attribute name="Type" use="required" type="xs:NCName"/>
  </xs:complexType>
</xs:element>

我现在有 bindings.xml

<jaxb:bindings version="1.0" 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"
           jaxb:extensionBindingPrefixes="xjc">

<jaxb:bindings schemaLocation="data.xsd">
    <jaxb:schemaBindings>
        <jaxb:package name="net.opengis.kml.v_2_2_0"/>
    </jaxb:schemaBindings>

    <jaxb:bindings node="xs:complexType[@name='DaysOfWeek']//xs:element[@ref='DaysOfWeek']">
      <jaxb:property name="ComplexDaysOfWeek"/>
    </jaxb:bindings>
    <jaxb:bindings node="xs:element[@name='DaysOfWeek']">
      <jaxb:factoryMethod name="ComplexDaysOfWeek"/>
    </jaxb:bindings>
</jaxb:bindings>

标签: jaxb

解决方案


您对生成的类有冲突。尝试添加:

<jaxb:bindings node="xs:element[@name='DaysOfWeek']//xs:complexType">
  <jaxb:class name="ComplexDaysOfWeekType"/>
</jaxb:bindings>

(也许没有//xs:complexType,不太确定。)


推荐阅读