users@jaxb.java.net

Re: Unmarshalling extended complexTypes

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 21 Jul 2004 17:34:03 -0700

> Now, every schema validation tool I try says my XML file is OK. JAXB
> validates the schema and generates the Java code. But when I try to
> unmarshall the file, I get an exception when it gets to an elment in B
> that isn't in A.

I don't know which validation tool you tried, but I can tell you that
your XML document is not even well-formed. So I'd say the JAXB RI is
behaving correctly by issuing an error.


> Is this on purpose, or a bug? What I want to say is that C elements can
> have any type of data as long as it is based on A. I know I could use
> the xsd:choice construct, but I don't want to, because specifying
> exactly which objects are acceptable is less elegant from a modeling
> perspective than just saying objects of a certain type are OK.

Please refer to schema books for more details on how to design a schema.

I think your intention is to say:

    <C xmlns="http://example.com/x" xsi:schemaLocation="...">
      <Cel xsi:type="B">
        <Ael>dsfadf</Ael>
        <Bel>dsfadfsa</Bel>
      </Cel>
    <C>

? (You still need to declare the xsi prefix)


I personally don't see how using @xsi:type is any more elegant than
using a choice, but that's your decision.


regards,
--
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net