With reference to [Pluggable ID/IDREF handling in JAXB 2.0|http://weblogs.java.net/blog/kohsuke/archive/2005/08/pluggable_ididr.html]
@XmlRootElement
class Apple { @XmlID String id; }
@XmlRootElement
class AppleRef { @XmlIDREF Object ref; }
@XmlRootElement
class Orange { @XmlID String id; }
@XmlRootElement
class OrangeRef { @XmlIDREF Object ref; }
class Box {
@XmlElementRef
List fruits;
}
Above code is generated from schema that describes following xml document
<document>
<box>
<appleRef ref="a1" />
<orangeRef ref="o1" />
<apple id="a1" />
<orange id="o1" />
</box>
<box>
<apple id="a2" />
<appleRef id="a2" />
</box>
</document>
Extract from the article:
Where orangeRefs would only refer to oranges and appleRefs would only refer to apples. (Note that this document no longer validates with the original schema.)
+First,{color:#ff0000} you'd have to modify{color} the above classes to make it clear that AppleRef only refers to Apple:+
@XmlRootElement
class AppleRef { @XmlIDREF Apple ref; }
@XmlRootElement
class OrangeRef { @XmlIDREF Orange ref; }
Is there a binding annotation for a schema document that indicates that class Object should be replaced by Apple and Orange classes? Thus, generation of java classes can be done without any manual modifications of classes OrangeRef and AppleRef.