gpt4 book ai didi

java - JaxB 属性值已定义。使用 to resolve this conflict

转载 作者:行者123 更新时间:2023-11-30 02:15:58 24 4
gpt4 key购买 nike

我正在使用以下 xsd 架构文件来生成 java 类

<xsd:complexType name="Instruction">
<xsd:choice>
<xsd:sequence>
<xsd:element name="InstructionIndicator" type="InstructionIndicator">
<xsd:annotation>
<xsd:documentation>some text</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:sequence minOccurs="0" maxOccurs="49">
<xsd:element name="MultipleTimingModifier" type="ANDOR"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>some text</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="TimingAndDuration" type="TimingAndDuration" />
</xsd:sequence>
</xsd:sequence>
<xsd:sequence>
<xsd:choice>
<xsd:element name="AdministrationIndicator" type="AdministrationIndicator">
<xsd:annotation>
<xsd:documentation>some text</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:sequence>
<xsd:element name="DoseAdministration" type="DoseAdministration" />
<xsd:element name="TimingAndDuration" type="TimingAndDuration">
<xsd:annotation>
<xsd:documentation>some text</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:sequence minOccurs="0" maxOccurs="49">
<xsd:element name="MultipleTimingModifier" type="ANDOR"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>some text</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="TimingAndDuration" type="TimingAndDuration" />
</xsd:sequence>
</xsd:sequence>
</xsd:choice>
<xsd:sequence minOccurs="0">
<xsd:element name="IndicationForUse" type="Indication"
maxOccurs="50">
<xsd:annotation>
<xsd:documentation>some text</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="IndicationClarifyingFreeText" type="an1..255"
minOccurs="0" />
</xsd:sequence>
<xsd:element name="MaximumDoseRestriction" type="MaximumDoseRestriction"
minOccurs="0" maxOccurs="50">
<xsd:annotation>
<xsd:documentation>some text</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:choice>

但是处理这个会导致错误

Property "MultipleTimingModifierAndTimingAndDuration" is already defined. Use <jaxb:property> to resolve this conflict.

为了解决这个问题,我编写了一个包含以下内容的绑定(bind)文件

<jaxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc" version="2.0">

<jaxb:bindings schemaLocation="structures.xsd"
node="//xs:complexType[@name='Instruction']/xs:choice[1]
/xs:sequence[1]/xs:sequence/xs:element[@name='MultipleTimingModifier']">
<jaxb:property name="MultipleTimingModifier1" />
</jaxb:bindings>

<jaxb:bindings schemaLocation="structures.xsd"
node="//xs:complexType[@name='Instruction']/xs:choice
/xs:sequence[1]/xs:sequence/xs:element[@name='TimingAndDuration']">
<jaxb:property name="TimingAndDuration1" />
</jaxb:bindings>

在 elcipse 中生成 Jaxb 类时添加此绑定(bind)文件后,会产生以下错误

compiler was unable to honor this property customization. It is attached to a wrong place, or its inconsistent with other bindings.

如果从目标序列节点中删除 maxoccurrs="49"约束,类将成功生成

注意:

  • 架构是 5 个不同文件的组合,超过 2000 行
  • 这里仅分享产生错误的部分

最佳答案

使用以下绑定(bind)代码我已经解决了我的问题

<jaxb:bindings
schemaLocation="structures.xsd"
node="//xs:complexType[@name='Instruction']/xs:choice/xs:sequence[1]/xs:sequence[1]">
<jaxb:property name="seq1"/>
</jaxb:bindings>

关于java - JaxB 属性值已定义。使用 <jaxb :property> to resolve this conflict,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48441532/

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