已定义JaxB属性值。使用< jaxb:property>解决此冲突

时间:2018-01-25 11:13:21

标签: java xml eclipse xsd jaxb

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

但是处理这会导致错误

  

属性“MultipleTimingModifierAndTimingAndDuration”已经定义。使用&lt; jaxb:property&gt;解决这个冲突。

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

<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类时,会生成以下错误

  

编译器无法遵循此属性自定义。它附着在错误的地方,或与其他绑定不一致。

如果从目标序列节点

中删除maxoccurs =“49”约束,则类将成功生成

注意:

  • 架构是5个不同文件的组合,超过2000行
  • 此处仅共享产生错误的部分
  • 如果您打算投票,请在评论中留下理由,以便我可以改进问题
  • 我已经尝试了所有现有的答案,但没有一个能为我工作

1 个答案:

答案 0 :(得分:1)

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

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