tags:

views:

33

answers:

1

According to this, you can make use of xs:key and xs:keyref when marshalling and unmarshalling data in JAXB 2.x.

However, I can't find a working example of this being done anywhere.

What we're doing is setting a lookup section in each XML message containing the details for the reference/code values (id, name, description, etc), and then have the data elements later in the message refer back to these items using their key. XML schema defines and supports this through xs:keyref and xs:key (xs:IDREF is not an allowed option).

What I'd like to do is have my JAXB unmarshaller follow these refs dynamically, replacing the key with the referenced object.

Could anybody refer me to an example of this being done?

+1  A: 

Are you talking about a compound key situtation?

<directory>
   <employee>
      <eID>123</eID>
      <country>CA</country>
   </employee>
   <employee>
      <eID>123</eID>
      <country>US</country>
   </employee>
   <employee>
      <eID>456</eID>
      <country>US</country>
   </employee>
   <phone-number>
      <contact eID="123" country="US"/>
   </phone-number>
</directory>

If so EclipseLink JAXB (MOXy) could be used:

Blaise Doughan
Thanks! I wasn't really thinking in terms of compound keys, but this works as a decent example of modelling a key reference.
Matthew Flynn