Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Failed to parse a schema by xjc in case of xs:choice

Tags:

java

jaxb

xsd

I'm want to generate java classes from a schema using jaxb, but I am getting a parsing error from xjc. I have 2 elements wrapped in a choice then one of the element is again repeated just after choice:

<xs:element name="A">
  <xs:complexType>
    <xs:choice>
      <xs:sequence maxOccurs="unbounded">
        <xs:element ref="X"/>
        <xs:element ref="Y"/>
      </xs:sequence>
      <xs:element ref="Y"/>
    </xs:choice>
  </xs:complexType>
</xs:element>

jaxb is throwing:

[ERROR] Element "{*something*}Y" shows up in more than one properties.
 line *something* of file:/*something*.xsd

PS: my jaxb version is 2.1.13

like image 207
Rahul Thakur Avatar asked Feb 22 '23 04:02

Rahul Thakur


1 Answers

Take a look at this post on SO. The solution is to provide a custom binding file that maps your Y outside the choice to use another property name.

I would probably also map the recurring sequence to a class with two properties (X and Y), but that's something else.

I've also tried a test schema (derived from yours, just added dummy complex elements for X and Y) with version 7.1 of the free NetBeans IDE and it worked out without any need for a custom binding file. The JAXB version that I've used is 2.2.4

like image 51
Petru Gardea Avatar answered Apr 07 '23 23:04

Petru Gardea