wood burning stoves 2.0*
The moose likes Web Services and the fly likes JAXB 1.0 External Binding Customization: Binding Duplicate Elements in XML Schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAXB 1.0 External Binding Customization: Binding Duplicate Elements in XML Schema" Watch "JAXB 1.0 External Binding Customization: Binding Duplicate Elements in XML Schema" New topic
Author

JAXB 1.0 External Binding Customization: Binding Duplicate Elements in XML Schema

Vivek Gupta
Greenhorn

Joined: May 02, 2005
Posts: 23
I have following xsd: Schema3.xsd

1. <?xml version="1.0"?>
2. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3. <xsd:include schemaLocation="../Schema1.xsd"/>
4. <xsd:include schemaLocation="../Schema2.xsd"/>
5. <xsd:complexType name="ModelAssembly">
6. <xsd:sequence>
7. <xsd:element name="ModelIdentifier" type="ModelIdentifier"/>
8. <xsd:element name="ModelIdentifier" type="ModelIdentifier" minOccurs="0"/>
9. <xsd:element name="ModelRelationship" type="ModelRelationship" maxOccurs="unbounded"/>
10. </xsd:sequence>
11. </xsd:complexType>
12. </xsd:schema>

**I CANNOT CHANGE THE XSD. THIS IS A VALID XSD, although not a good design **

What mapping can I follow in an external bindings.xjb file to generate the Java Classes successfully.

I get the following error during JAXB compiler run-

[ERROR] A class/interface with the same name "ModelIdentifier" is already in use. line 8 of Schema3.xsd

[ERROR] (Relevant to above error) another one is generated from here. line 7 of Schema3.xsd

I have the work-around with the inline-customization - introducing the xsd:annotation & xsd:appinfo elements combined with jaxb:class declaration within any one of the ModelIdentifier element in the above Schema. But I need it in an external bindings file.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Since you did not enclose the imported XML schemas, I replaced the imported types as follows:


Then using XJC from the Java SE 6 JDK I successfully generated four java files, specifying only the destination directory of the generated files and the XML schema to use (the above).
Would it be possible for you to show the imported schemas too?
Best wishes!
Vivek Gupta
Greenhorn

Joined: May 02, 2005
Posts: 23
hi Ivan,
I tried compiling the Schema in your post using JAXB compiler, but getting the following error

C:\>xjc Sample.xsd
parsing a schema...
[WARNING] Schema contains no global element declaration.
unknown location

[ERROR] A class/interface with the same name "generated.ModelAssembly.ModelIdentifier" is already in use.
line 19 of Sample.xsd


[ERROR] (Relevant to above error) another one is generated from here.
line 18 of Sample.xsd

Failed to parse a schema.
---------------------------------------------------------------------------------------------------------------------------------
C:\>xjc -version
xjc version "1.0.2-b15-fcs"
JavaTM Architecture for XML Binding(JAXB) Reference Implementation, (build 1.0.2-b15-fcs)


Is the error due to earlier version of JWSDP - JAXB RI 1.0.2 I am using?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Your version of XJC does seem a little old, here is the version information from my XJC:
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)


Would it be possible for you to upgrade?
Best wishes!
Vivek Gupta
Greenhorn

Joined: May 02, 2005
Posts: 23
hi,
Cannot upgrade the JAXB version, since the Client Application using the generated classes is still on JDK 1.4.

However solved the issue, with JAXB external binding customization - reaching the First Element using XPath expression for the 1st child element of context node "ModelAssembly".



This worked.
Thanks.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Thanks for sharing your solution!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JAXB 1.0 External Binding Customization: Binding Duplicate Elements in XML Schema
 
Similar Threads
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"AirAvailabilityRS")
validating xml against xml schema using xml spy
Error While Testing Webservice using Web service Explorer in RAD
error in wsdl
Castor SourceGenerator exception