I've XML document. From XML DTD I've generated Java classes. For example, XML
<root>
<parent name="parentName">
<child />
</parent>
</root>
gives me classes Root.java, Parent.java (witd List<Child> getChild() method) and Child.java. So now I can call unmarshall:
JAXBContext jc = JAXBContext.newInstance("mygeneratedpackage");
Unmarshaller unmarshaller = jc.createUnmarshaller();
Root root = (Root) unmarshaller.unmarshal(new File("my.xml"));
List parentList = root.getParent();
Iterator iterator = parentList.iterator();
while ( iterator.hasNext() ){
...
}
I can iterate to Child. But what if I want to go back from Child to Parent? Is there any way how to generate pointer from child to parent? I've found afterUnmarshal callback, so I can add
@XmlTransient
private Parent parent;
...
public void afterUnmarshal(Unmarshaller u, Object parent) {
this.parent = (Parent) parent;
}
to Child.java class, but I have to add this manually after each generatig Java classes from XML DTD file. Is there any way how to do it automatically?
Thanks for any help.
Sorry for my poor English.