users@jaxb.java.net

Restricting xs:anyType

From: Thomson, Martin <Martin.Thomson_at_andrew.com>
Date: Tue, 22 Apr 2008 00:41:40 -0500

Hi all, I've got an issue with a set of schema that use restrictions of xs:anyType to mark extension points. JAXB is unmarshalling instance documents to DOM elements, rather than the classes that it has generated. XJC generates empty classes for the extending class, which means that JAXB does not find the generated classes for any local elements declared by the extending type. It's probably best to illustrate by example: I have a simple base schema (A): <complexType name="baseType"> <complexContent> <restriction base="anyType"> <sequence> <any minOccurs="0" maxOccurs="unbounded" processContents="lax" /> </sequence> </restriction> </complexContent> </complexType> And in the extending schema (B), this base type is extended to include a concrete definition of its content: <element name="ext" type="b:extendingType" /> <complexType name="extendingType"> <complexContent> <restriction base="a:baseType"> <sequence> <element name="one" type="token" /> <element name="two" type="token" /> </sequence> </restriction> </complexContent> </complexType> I then unmarshal the following instance document: <ext> <one>string</one> <two>string</two> </ext> JAXB produces the following model: JAXBElement<ExtendingType> value = ExtendingType any = List<Object> [1] = org.w3c.dom.Element ("one", "string") [2] = org.w3c.dom.Element ("one", "string") The problem seems to arise from the fact that the extending class is generated as a completely empty class and no annotations are added that would enable the use of the generated classes. Since the elements are local, they don't appear in the ObjectFactory. Making the elements global ensures that JAXB sees the elements (because the elements are put in the ObjectFactory). I am looking for a work-around that doesn't involve changing schema. Has anyone got a suggestion for me? Cheers, Martin ------------------------------------------------------------------------------------------------ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any unauthorized use of this email is prohibited. ------------------------------------------------------------------------------------------------ [mf2]