Error: failed to parse xjc scheme in case of xs: choice

I want to generate java classes from a schema using jaxb, but I get a syntax error from xjc. I have 2 elements wrapped in a selection, then one of the elements is repeated again immediately after the selection:

<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 throws:

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

PS: my jaxb version 2.1.13

+4
source share
2 answers

Take a look at this post on SO . The solution is to provide a custom binding file that displays Y out of choice to use a different property name.

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

I also tried a test circuit (derived from your just added dummy complex elements for X and Y) with version 7.1 of the free NetBeans IDE, and it was developed without the need for a binding file. The JAXB version I used is 2.2.4

+6
source

I also tried to make it work, as I described to Peter. Rahul did not post his decision, so here is my binding file.

 <?xml version="1.0" encoding="UTF-8"?> <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.1"> <jaxb:bindings schemaLocation="test.xsd" node="//xs:element[@name='A']/xs:complexType/xs:choice[1]"> <jaxb:property name="OutsideY"/> </jaxb:bindings> </jaxb:bindings> 

XJC Output:

 $xjc -version xjc version "JAXB 2.1.10 in JDK 6" JavaTM Architecture for XML Binding(JAXB) Reference Implementation, (build JAXB 2.1.10 in JDK 6) $xjc -p com.example.test -d src -extension -b bindings.xml test.xsd parsing a schema... compiling a schema... com\example\test\A.java com\example\test\ObjectFactory.java 
+2
source

Source: https://habr.com/ru/post/1401173/


All Articles