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

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

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

java, 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  Failed to parse a schema. This message: [ Message body] [ More options (top, bottom) ] Related messages: [ Next message] [ Previous message] [ Next in thread] [ Replies] Contemporary messages sorted: [ by date] [ by thread] [ by subject] [ by author] [ by messages with attachments]

I've also tried to make it work as Petru described. Rahul hasn't posted his solution so here my bindings 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

Multiple <any /> elements on a schema : second element is not , An XML schema is mapped via JAXB to java objects with multiple elements. I have the same kind of case in a XSD (i.e. a sequence of 2 any elements with line 22 of file:/C:/Temp/binding.xjb [ERROR] (the above customization is attached to the in the schema) line 8 of file:/C:/Temp/test.xsd Failed to parse a schema. Next message: Wolfgang Laun: "Re: Failed to parse Schema" Previous message: Aleksei Valikov: "Re: XJC Plugin: turn of creation of ObjectFactory (or replace ObjectFactory with an own)" Next in thread: Wolfgang Laun: "Re: Failed to parse Schema" Reply: Wolfgang Laun: "Re: Failed to parse Schema"

Maybe someone will read this: org.jvnet.jaxb2_commons . jaxb2-basics is not working on references ! I have really tried many ways to make this plugin work, and you just can't. (It is also mentioned on github page)

@Stanislav Mamontov helped me a lot.

If somebody is curious, this also works for groups:

XSD:

<xsd:group name="OpticalID">
<xsd:sequence>
  <xsd:choice>
    <xsd:sequence>
      <xsd:group ref="MPCID"/>
      <xsd:element ref="trkSub" minOccurs="0"/>
    </xsd:sequence>
    <xsd:sequence>
      <xsd:element ref="trkSub"/>
    </xsd:sequence>
  </xsd:choice>
</xsd:sequence>

BINDING:

<jaxb:bindings node="xsd:group[@name='OpticalID']//xsd:sequence[1]/xsd:choice[1]/xsd:sequence[1]/xsd:element[@ref='trkSub']">
    <jaxb:property name="trkSubOrNull"/>
</jaxb:bindings>

XJC unable to parse xsd and generate java classes (XML forum at , xjc even.xsd , I am getting the error , parsing a schema [WARNING] schema_reference.4: Failed to read schema document <xs:complexType>. <xs​:sequence> In your case here, the most probable reason is that of 2). Re: Failed to parse a schema This message : [ Message body ] [ More options ( top , bottom ) ] Related messages : [ Next message ] [ Previous message ] [ In reply to ] [ Next in thread ]

JAXB XJC compiling Issue (XML forum at Coderanch), <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; elementFormDefault="qualified" <xs:sequence> <xs:choice minOccurs="0" maxOccurs="unbounded"> parsing a schema. [ERROR] Element "test1" shows up in more than one properties. [JAXB] Not able to generate IMPL file using xjc. I am attempting to generate the Java classes for the attached XLM schema (JMdict_e.xsd) using the following command:

Customizing JAXB Bindings, In most cases, the default bindings generated by the JAXB binding compiler will be <jxb:bindings schemaLocation="po.xsd" node="/xs:schema"> in the parsing and printing of valid lexical representations of the XML Schema built-in datatypes. the JAXB binding compiler with the ant fail command, the following error  Next message: pasupulathisp: "Re: Failed to parse Schema" Previous message: pasupulathisp: "Failed to parse Schema" In reply to: pasupulathisp: "Failed to parse Schema" Next in thread: pasupulathisp: "Re: Failed to parse Schema" Reply: pasupulathisp: "Re: Failed to parse Schema"

JAXB and musicxml.xsd?, Failed to parse a schema. ---<snip>--- Has anyone managed to use the MusicXML XSD with JAXB? (And yes, I I will post the 20-line bug example in another message, in case someone on the MusicXml list could give us a hand. Bye Removing the "function" line, and leaving just the choice between Failed to parse Schema. Hi, I am trying to run xjc command on my schema and i get the following exception.I tried with SDK 1.4and 1.6.But both produce the same error.

Comments
  • Is your version of JAXB a "must" requirement? Can you move to the latest? I've tested with the latest available with Java 7 and it works without need to custom binding file.
  • no it is not a must, it's just that i am currently using 2.1.13 & in any slim case if it was a version issue of some kind, so just clearing things out.
  • i am sorry, but the jaxb version is not changeable. and i am still unable to get the binding to work! help!
  • i have to use 2.1.13 and cannot change the version now. and i am still facing problems with the binding, i tried to pack the sequence inside the choice in a class, but only complexType can be put inside a class. also there is no use of binding property name with different name <jaxb:bindings node="-XPath-"> <jaxb:property name="OutsideY"/> </jaxb:bindings> it is not giving any errors while reading the binding file, but not doing anything with it also! and i am sure that i have no XPath issue.
  • @Petru, Could you please confirm if this works in JAXB 2.2.4 ? because I tried above schema and it shows error of [ERROR] cos-nonambig:. I use xjc 2.2.4-2
  • EDIT: I see I use maxoccurs in all elements. Its ok. thanks