users@jaxb.java.net

Re: JAXB multiple schemas with element reference

From: Alexander Broekhuis <a.broekhuis_at_gmail.com>
Date: Tue, 8 Mar 2011 09:18:18 +0100

On 8 March 2011 09:13, Wolfgang Laun <wolfgang.laun_at_gmail.com> wrote:

>> 2) Generate the code in a package per namespace (how can I do this?),
>> and ignoring the namespace of the first schema (since it is already in
>> a package somewhere).
>
> But B.xsd is targeted into namespace ".../B". If you omit the -d
> srcgen/{a,b},
> you'll get A.xsd into org/.../a and stuff from B.xsd into org/.../b.
>
> You could build the common part A.xsd -> .java -> .class in one place.
>
> Builds B.xsd + A.xsd, C.xsd + A.xsd,... could be done wherever convenient;
> just discard the result from A.xsd and refer to the common part.
>
> Even generating the stuff from A.xsd again with each project would not
> scare me too much as long as I can make sure that all build from the same
> XML schema using the same compiler.

This will only work if the package isn't explicitly set, hence the
question for setting a different package per namespace. But I could as
well keep the auto generated package, and in that case simply
ignore/discard the results from A as you suggested.

Thanks for your time and help!

>
> -W
>
>>
>> I'd like to be able to keep the separation of the schemas and
>> generated code, but for (2) to work, I need to generate part of the
>> second schema in a different package. Is this possible using an xpath
>> expression and a binding file? The part for the different schema has
>> the same namespace as the first schema has, and therefor can be
>> discarded.
>>
>> >
>> > -W
>> >
>> >
>> >>
>> >> Thanks in advance!
>> >>
>> >> On 3 March 2011 13:41, Alexander Broekhuis <a.broekhuis_at_gmail.com>
>> >> wrote:
>> >> > Hi,
>> >> >
>> >> > I've created an example. As can be seen, generating a model for
>> >> > B.xsd,
>> >> > also generates a ObjectFactory for an element from A.xsd. The content
>> >> > of this ObjectFactory is already in the generated files for A.xsd.
>> >> >
>> >> > A.xsd:
>> >> > ---------
>> >> > <?xml version="1.0" encoding="UTF-8"?>
>> >> > <schema elementFormDefault="qualified"
>> >> > xmlns="http://www.w3.org/2001/XMLSchema"
>> >> >        xmlns:a="http://www.example.org/A/"
>> >> >        targetNamespace="http://www.example.org/A/">
>> >> >
>> >> >    <element name="someType" type="a:SomeType"></element>
>> >> >
>> >> >        <complexType name="SomeType">
>> >> >                <sequence>
>> >> >                        <element name="field" type="string"></element>
>> >> >                </sequence>
>> >> >                <attribute name="attr" type="string" />
>> >> >        </complexType>
>> >> >
>> >> > </schema>
>> >> >
>> >> > --------
>> >> > B.xsd
>> >> > --------
>> >> > <?xml version="1.0" encoding="UTF-8"?>
>> >> > <schema elementFormDefault="qualified"
>> >> >    xmlns="http://www.w3.org/2001/XMLSchema"
>> >> >    xmlns:b="http://www.example.org/B/"
>> >> >    xmlns:a="http://www.example.org/A/"
>> >> >    targetNamespace="http://www.example.org/B/">
>> >> >
>> >> >    <import namespace="http://www.example.org/A/" />
>> >> >
>> >> >    <complexType name="SomeTypeGroup">
>> >> >        <sequence>
>> >> >                <element ref="a:someType" minOccurs="1"
>> >> > maxOccurs="unbounded" />
>> >> >        </sequence>
>> >> >    </complexType>
>> >> >
>> >> >
>> >> >    <element name="root" type="b:RootType"></element>
>> >> >    <complexType name="RootType">
>> >> >        <sequence>
>> >> >                <element name="someTypes" type="b:SomeTypeGroup" />
>> >> >        </sequence>
>> >> >    </complexType>
>> >> > </schema>
>> >> >
>> >> > ---------
>> >> > catalog.xml
>> >> > ---------
>> >> > <?xml version="1.0" encoding="UTF-8"?>
>> >> > <catalog
>> >> >  xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
>> >> >
>> >> >  <public publicId="http://www.example.org/A/"
>> >> >    uri="A.xsd"/>
>> >> >
>> >> > </catalog>
>> >> >
>> >> > --------
>> >> > Shell commands
>> >> > --------
>> >> > mkdir srcgen
>> >> > mkdir srcgen/a
>> >> > mkdir srcgen/b
>> >> > xjc -d srcgen/a -episode a.episode A.xsd
>> >> > xjc -d srcgen/b B.xsd -b a.episode -catalog catalog.xml -extension
>> >> > -classpath srcgen/a
>> >> >
>> >> > --------
>> >> >
>> >> >
>> >> > On 2 March 2011 21:08, Alexander Broekhuis <a.broekhuis_at_gmail.com>
>> >> > wrote:
>> >> >> Hi,
>> >> >>
>> >> >> Thx for your reply.
>> >> >>
>> >> >> On 2 March 2011 18:32, Wolfgang Laun <wolfgang.laun_at_gmail.com>
>> >> >> wrote:
>> >> >>> There is no connection of the type/class names EventType and
>> >> >>> TypeType
>> >> >>> to the
>> >> >>> schema snippets. Please clarify this. A complete working example
>> >> >>> reproducing
>> >> >>> the effect would help.
>> >> >>
>> >> >> I "edited" my working example to something simpler, and forgot to
>> >> >> rename that one EventType. I will create a small working example
>> >> >> tomorrow.
>> >> >>
>> >> >>>
>> >> >>> But is it really necessary to use an episode file? Ususally,
>> >> >>> compiling
>> >> >>> all
>> >> >>> in one run is the way to go.
>> >> >>
>> >> >> The project I need this for is split into multiple parts. One scheme
>> >> >> belongs to a basic module, and can be extended by other modules. So
>> >> >> yes, unfortunately in this case it is needed.
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Met vriendelijke groet,
>> >> >>
>> >> >> Alexander Broekhuis
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Met vriendelijke groet,
>> >> >
>> >> > Alexander Broekhuis
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Met vriendelijke groet,
>> >>
>> >> Alexander Broekhuis
>> >
>> >
>>
>>
>>
>> --
>> Met vriendelijke groet,
>>
>> Alexander Broekhuis
>
>



-- 
Met vriendelijke groet,
Alexander Broekhuis