问题描述
我想在子对象和父对象之间的类中使用双向导航方法。
IDREF在我的情况下是不够的,因为我不想指定父的le id。从这样的xsd可以清楚地看到
:
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>
我希望课程如下:
class A {
...
public List<B> getB() { ...}
...
}
class B {
...
public A getA() {
...
}
我的xml必须如下所示:
and my xml must looks like this:
<a id="a1">
<b id="b1"/>
<b id="b2"/>
...
</a>
在unmarshal之后,我希望能够将A导航到Bs并从B导航到A(通过b.getA())!!
这是一个非常基本的功能,但我找不到一种简单的方法来实现这一目标...
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 ...
任何想法??
提前致谢
推荐答案
您可以 在Unmarshal之后无效(Unmarshaller,Object parent)
被调用...好吧,在解组并根据需要设置对象树。
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父子父导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!