• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vivek Gupta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for sharing your solution!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic