users@jaxb.java.net

Re: Extensible soutions using JAXB?

From: Raymond Wold <raymond.wold_at_teletopia.com>
Date: Thu, 24 May 2007 09:46:45 +0200

Andrew Hughes wrote:
> Hi All,
>
> 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.

It goes a bit counter to the idea of W3C XML Schemas, type safety and such,
but there is the <any> tag you can use in your XSD; this would produce a
List<org.w3c.dom.Element> in the java code generated by XJC.

Personally I would recommend you simply make it easier for people to provide
their own schemas to what you are doing, so they can define what extra
structure they need and compile their own classes.