views:

375

answers:

1

We are using JAXB to map Java classes into XML files. Currently we use the Java-to-XSD approach by annotating the Java classes.

This works fine in general but we've hit the following problem now: we want an attribute of one XML element to refer to another XML element by it's name/ID. Imagine some XML describing a conceptual schema, with the entities defined in <entity> elements and <property> elements used to establish the links. The @type attribute of the properties should then reference an entity in the same file.

Is it possible to model this using JAXB? What I imagine is having xsd:key and xsd:keyref elements in the schema which should then be resolved to the matching Java objects when unmarshalling.

A: 

It's non-trivial, but possible:

http://weblogs.java.net/blog/2005/08/15/pluggable-ididref-handling-jaxb-20

skaffman
That solves my problem to some extent, but not entirely. I would like to have proper support for the references in the XSD file. xsd:key/xsd:keyref give you scope (and typing) for the references and are supported by some XML editors. ID/IDREF are much more primitive.
Peter Becker