users@jaxb.java.net

Re: Extensible soutions using JAXB?

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Thu, 24 May 2007 09:49:08 +0200

Hi.

I have asked this before and I'm still hunting a solution.... If an
> unexpected element is added to the XML content, how can I use JAXB to
> handle this? I know I can simply ignore this. But that is not need to
> know how to read and write customized/extended elements/attributes to
> the document.
>
> Example, my XSD and JAXB bindings expect the following content:
> <Person>
> <Name>Homer Simpson</Name>
> <Occupation>Nuclear Technician</Occupation>
> </Person>
>
>
> However, the use of this information model doesn't meet my needs, and
> the need for an element not found in the XSD needs to be added...
> <Country>
> <Person>
> <Name>Homer Simpson</Name>
> <Occupation>Nuclear Technician</Occupation>
> <Country>USA</Country>
> </Person>
>
>
> I am trying to provide an open source implementation a standards body
> has defined to an existing open source project. The community likes what
> I have done, but all continiously request that I provide support for
> what is described above. If this can be done with JAXB then I really
> want to know how.
>

There were a couple of good articles on the topic (search for "writing
extensible XML Schemas").

If you use XJC to compile your schema, only those fields defined in the
schema for the moment of compilation will appear in the object model.
"Extension" elements will not appear there. But I think you can use a
combination of xs:any and xjc:dom customization to simply have the as
org.w3c.dom.Elements in yout objects.

Bye.
/lex