Thanks Han,
That seems to work perfectly. You mentioned further customizations in the
documentation. I must have missed this in the documentation. Can you
point it
out to me?
Thanks again,
Chris
Han Ming Ong
<hanming_at_mac.com> To: JAXB-INTEREST_at_java.sun.com
Sent by: cc:
Discussion list Subject: Re: JAXB one-to-many relationship problems.
for the Java
Architecture for
XML Binding
<JAXB-INTEREST_at_ja
va.sun.com>
04/08/2003 12:17
PM
Please respond to
Discussion list
for the Java
Architecture for
XML Binding
On Tuesday, April 8, 2003, at 08:25 AM, SUBSCRIBE JAXB-INTEREST
CBroussard wrote:
> Hi All,
>
> I'm relatively new to jaxb and am experiencing problems.
>
> I'm trying to bind a one to many relationship and it doesn't seem to
> work
> for me.
>
> a sample xml file would be
>
> <root>
> <book>
> <title />
> <authors>
> <author>
> <firstname />
> <lastname />
> </author>
> <author>
> <firstname />
> <lastname />
> </author>
> </authors>
> </book>
> </root>
>
> i'm trying to bind through xml schemas instead of dtd.
>
> here's a sniplet.
>
> <xsd:complexType name="AuthorsType">
> <xsd:sequence>
> <xsd:element name="author" type="author"
> maxOccurs="unbounded"
> />
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="author">
> <xsd:sequence>
> <xsd:element name="firstname" type="xsd:string" />
> <xsd:element name="lastname" type="xsd:string" />
>
> </xsd:sequence>
> </xsd:complexType>
>
> when i run it through xjc, it generates the interface of
>
> public interface AuthorsType {
> java.util.List getAuthor();
> }
>
> i want to see something like this???
>
> public interface AuthorsType {
> java.util.List getAuthor();
> void setAuthor(int index, Author author);
> }
>
> interface Author generates the correct interface.
>
> What am I doing wrong? I have tried many different configurations for
> the
> xsd file. However, this is the closest I've gotten thus far.
>
> Thanks,
>
> Chris
Setting the following right after the <schema> element as customization
will get you the 2nd method but now the 1st returns you a Java array.
<xs:annotation>
<xs:appinfo>
<jxb:globalBindings collectionType="indexed"/>
<jxb:schemaBindings>
<jxb:package name="com.my.package.name"/>
</jxb:schemaBindings>
</xs:appinfo>
</xs:annotation>
Han Ming
ps: there are more customizations that you can do, after reading the
documentation.