users@jaxb.java.net

Re: Polymorphism and Code generation

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 17 Dec 2008 13:17:37 +0100

Hi.

> Hi, I have a problem with code generation (xjc) and inheritance. The
> following xml structure exists: some content some content some content a, b
> and c shall have the same super class My xsd looks like this: SOME CONTENT
> SOME CONTENT SOME CONTENT xjc creates five classes (A, B, C, X and Super).
> Unfortunately, X has three lists: Lista; Listb and List c; That is not what
> I want. I would prefer having only one list List super; In order to do this
> I could modify the generated code with annotations: @XmlELements({
> @XmlElement(name="a", type=A.class), @XmlElement(name="b", type=B.class),
> @XmlElement(name="c", type=C.class) }) List super; How must I write the xsd
> or the binding file to achieve this behaviour with code generation? The goal
> ist to have only one list although I have three different XML tags (a, b,
> c). Regards Ingrid


Please repost with better formatting, XML was not visible.

Concerning your question, you'll probably need to make something like:

<xsd:choice maxOccurs="unbounded">
  <xsd:element name="a" type="A"/>
  <xsd:element name="b" type="B"/>
  <xsd:element name="c" type="C"/>
</xsd:choice>

Bye.
/lexi