Reputation: 15
I am using JAXB 2.0 to generate POJO . I have the following XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="test">
<xs:complexType>
<xs:attribute name="system" type="xs:string"/>
<xs:attribute name="dim" type="xs:integer"/>
</xs:complexType>
</xs:element>
<xs:element name="test1" type="xs:string"/>
<xs:element name="test2" type="xs:string"/>
<xs:element name="scoring_guide" type="embedded_scoring_guide_type"/>
<xs:complexType name="embedded_scoring_guide_type">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="test"/>
<xs:element ref="test1"/>
</xs:choice>
<xs:choice>
<xs:element ref="test2" maxOccurs="unbounded"/>
</xs:choice>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="test"/>
<xs:element ref="test1"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:schema>
When I am trying to generate POJO out of the above Schema .I am getting the below error:
Gennerating jaxb objects for C:\WORKAREA\JAXB\SubSeqenceElementCall\schema\SubSequentElementCall.xsd Using XJC generator...
parsing a schema...
[ERROR] Property "TestOrTest1" is already defined. Use <jaxb:property> to resolve this conflict.
line 14 of file:/C:/WORKAREA/JAXB/SubSeqenceElementCall/schema/SubSequentElementCall.xsd
[ERROR] The following location is relevant to the above error
line 21 of file:/C:/WORKAREA/JAXB/SubSeqenceElementCall/schema/SubSequentElementCall.xsd
[ERROR] Element "test1" shows up in more than one properties.
line 21 of file:/C:/WORKAREA/JAXB/SubSeqenceElementCall/schema/SubSequentElementCall.xsd
[ERROR] The following location is relevant to the above error
line 14 of file:/C:/WORKAREA/JAXB/SubSeqenceElementCall/schema/SubSequentElementCall.xsd
Failed to parse a schema.
Gennerating jaxb objects for C:\WORKAREA\JAXB\SubSeqenceElementCall\schema\SubSequentElementCall.xsd Completed!
Please help on the above issue.
Thanks Vikram
Upvotes: 1
Views: 1848
Reputation: 2416
Try to define JAXB inline properties or binding file or avoid anonymous sequences/choices with same fields.
This is JAXB inline binding sample to solve your problem:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="1.0">
<xs:element name="test">
<xs:complexType>
<xs:attribute name="system" type="xs:string"/>
<xs:attribute name="dim" type="xs:integer"/>
</xs:complexType>
</xs:element>
<xs:element name="test1" type="xs:string"/>
<xs:element name="test2" type="xs:string"/>
<xs:element name="scoring_guide" type="embedded_scoring_guide_type"/>
<xs:complexType name="embedded_scoring_guide_type">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<!-- Additional JAXB annotations -->
<xs:annotation>
<xs:appinfo>
<jxb:property name="firstBlock"/>
</xs:appinfo>
</xs:annotation>
<xs:element ref="test"/>
<xs:element ref="test1"/>
</xs:choice>
<xs:choice>
<xs:element ref="test2" maxOccurs="unbounded"/>
</xs:choice>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<!-- Additional JAXB annotations -->
<xs:annotation>
<xs:appinfo>
<jxb:property name="secondBlock"/>
</xs:appinfo>
</xs:annotation>
<xs:element ref="test"/>
<xs:element ref="test1"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:schema>
Also look at Oracle docs http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/JAXBUsing4.html
Upvotes: 2