JAXB - Example of following a keyref when unmarshalling

笑着哭i 提交于 2020-01-24 10:51:26

问题


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:


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:

  • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JPA/CompoundPrimaryKeys


来源:https://stackoverflow.com/questions/3189673/jaxb-example-of-following-a-keyref-when-unmarshalling

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!