JAXB/XJC 父子父导航 [英] JAXB / XJC parent-child-parent navigation

查看:25
本文介绍了JAXB/XJC 父子父导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在子对象和父对象之间的类中使用双向导航方法.IDREF 在我的情况下是不够的,因为我不想指定父级的 le id.明确地说,来自这样的 xsd:

<xs:序列><element name="b" type="B" minOccurs="0" maxOccurs="unbounded"></element></xs:sequence><属性名称=id"类型=ID"></attribute></complexType><complexType name="B"><属性名称=id"类型=ID"></attribute></complexType>

我希望类看起来像这样:

class A {...公共列表<B>getB() { ...}...}B类{...公共一个 getA() {...}

而我的 xml 必须如下所示:

<b id="b1"/><b id="b2"/>...</a>

解组后,我希望能够将 A 导航到 B 以及从 B 导航到 A(通过 b.getA())!这是一个非常基本的功能,但我没有找到一种简单的方法来实现...

有什么想法吗??

提前致谢

您可以创建一个方法 void afterUnmarshal(Unmarshaller, Object parent) 被调用......好吧,在解组并根据需要设置对象树之后.>

i would like to have bidirectional navigation methods in classes between child object and parent object. IDREF is not enough in my case because I don't want to specify le id of parent. to be clear, from an xsd like that:

<complexType name="A">
    <xs:sequence>
        <element name="b" type="B" minOccurs="0" maxOccurs="unbounded"></element>
    </xs:sequence>
    <attribute name="id" type="ID"></attribute>
</complexType>
<complexType name="B">
    <attribute name="id" type="ID"></attribute>
</complexType>

i would like classes looks like this:

class A {
    ...
    public List<B> getB() { ...}
    ...
   }
class B {
    ...
    public A getA() {
    ...
}

and my xml must looks like this:

<a id="a1">
    <b id="b1"/>
    <b id="b2"/>
    ...
</a>

After unmarshal, I would like to be able to navigate A to Bs AND from B to A (via b.getA()) !! It a very basic feature, but I don't find a simple way to achieve that ...

Any idea ??

Thanks in advance

解决方案

You can create a method void afterUnmarshal(Unmarshaller, Object parent) that gets called... well, after unmarshalling and set up your object tree as you need it.

这篇关于JAXB/XJC 父子父导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆