Problem Using JAXB with an Extension XML and It's Base
I am using JAXB to generate a class structure based on two XML schemas---say, Base.xsd and Extension.xsd. Both of these schemas declare their own namespace for their respective types. Base.xsd contains a complexType of some type, let's say "Person," as well as some more types that are put inside of person such as "Eyes" and "Hair," and there is also an "any" tag in Person. Extension.xsd defines some other complexTypes such as "Shirt" and "Shoes." There already exists an application which emits XML that is validated on Base.xsd and Extension.xsd, and uses "Person" such that "Person" contains "Eyes," "Hair," "Shirt," and "Shoes."
I cannot change the form of the XML being emitted by the application, which must be validated against Base.xsd and Extension.xsd, but I can change Extension.xsd (as long as the emitted XML in its present form can still be validated against it).
Now, because I've had to generate these class models in two separate calls to xjc (one for each schema), JAXB will generate a Person class such that Person only contains Eyes and Hair. Of course, this is problematic in any application that subscribes to the JAXB generated model, because we would like to have type-safe access to Shirt and Shoes from Person.
My first naive attempt to resolve this issue was to redefine Person in Extension.xsd such that it contains a Shirt element and a Shoes element. However, I've since realized that this is impossible because a redefined type must exist in the same namespace as it's original form.
I've also been working on sort of a hybrid schema so that Base.xsd and Extension.xsd can be combined by cutting and pasting to declare a Person with all the desired elements--including the type definitions. This hybrid can be used to generate the right class structure and then ignored. This is somewhat tedious however, as the actual schemas in question are quite a bit more lengthy and more complicated. I'm also experiencing some namespace issues that--again, due to my naivety regarding XML schemas--might doom the hybrid effort.
The hybrid schema method seems a kludge in itself, but it's certainly preferable to having the subscriber to the JAXB model extract the types through Person's "getAny()" method.
EDIT: Originally posted here: http://forums.java.net/jive/thread.jspa?messageID=483345񶀑
Message was edited by: etherealstill