users@jaxb.java.net

Re: Please help with educating me on the jaxb bindings to deal with duplicate elements in mutliple .xsd files.

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Thu, 14 Jul 2011 08:03:30 +0200

1) Can't you compile the 4 .xsd files independently, i.e., in 4 xjc runs?

I don't think you can unify all 4 halign entries into a single class -
according to your xjb you put them into different packages. If some or all
of the .xsd files have their elements in the same target namespace you would
get the same class, generated 4 times, but that doesn't matter.

2) You *are *in control of the .xsd files as far as their technical
structure is concerned. If they are poorly structured, you can
(XSLT-)transform them into another one, where the halign occurs in a (new)
common.xsd and the others just include common.xsd. Repeated includes don't
hurt.

-W



On 13 July 2011 22:47, Jarrod Roberson <jarrod_at_vertigrated.com> wrote:

> I asked the question on stackoverflow.com
> http://stackoverflow.com/questions/6681265/
>
> I have 4 .xsd files that I want to auto-generate code for. A couple of the
> files have duplicate names that clash when I try to generate all of them at
> the same time.
>
> When I get these 4 working I have about a hundred files to process. But I
> am just focusing on 4 of these files for now. I am not in control of them,
> they are from a vendor, so adding something to every one of them is not an
> option, neither is deleting the offending duplicates.
>
> I am using the maven-jaxb2-plugin to process these files.
>
> I am getting the following error when I try and generate code from my .xsd
> files.
>
> [ERROR] Error while parsing schema(s).Location [ file:/C:/Users/Jarrod%20Roberson/Projects/spa-tools/spa-lib/src/main/sc
>
> hema/mac-stylesheet-3.4.xsd{165,33}].
>
> org.xml.sax.SAXParseException: 'halign' is already define
>
> Here is my binding.xjb file
>
> <?xml version="1.0" encoding="UTF-8"?>
> <jxb:bindings version="2.1"
>
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
>
> xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
>
> xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
>
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
> xsi:schemaLocation=" http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd">
>
> <jxb:bindings schemaLocation="mac-3.4.xsd">
>
> <jxb:schemaBindings>
>
> <jxb:package name="my.company.mac"/>
>
> </jxb:schemaBindings>
>
> </jxb:bindings>
>
> <jxb:bindings schemaLocation="mac-stylesheet-3.4.xsd">
>
> <jxb:schemaBindings>
>
> <jxb:package name="my.company.stylesheet"/>
>
> </jxb:schemaBindings>
>
> </jxb:bindings>
> </jxb:bindings>
>
> here is the offending element that is in multiple files, all the same
> definition, this appears in both .xsd files.
>
> <xsd:simpleType name="halign">
>
> <xsd:restriction base="xsd:string">
>
> <xsd:enumeration value="left" />
>
> <xsd:enumeration value="center" />
>
> <xsd:enumeration value="right" />
>
> </xsd:restriction>
>
> </xsd:simpleType>
>
>
> I would ideally like duplicate entries to all point to the implemenation of
> the very first entry if at all possible.
>
> --
> Jarrod Roberson
> 678.551.2852
>