Reputation: 7275
I'm given multiple XSD-files A.xsd
, B.xsd
and C.xsd
, which reference each others elements via XInclude using IDREF
and ID
without cyclic dependencies. A.xsd
is my root file in the hierarchy.
With XJB and binding files I managed it to generate coherent Java Code from the XSDs.
After successfully creating Java objects a
, b
and c
, I'm trying to marshal them into XML files. This is where i get stuck.
When marshaling a
into a file a.xml
, b
and c
are stored nowhere and a.xml
contains no references to them.
How do I store all objects plus references successfully?
I have the following approaches at hand, but they are not sutable:
b
and c
directly in my a.xsd
instead of using IDREF
. Doesn't work because I want multiple XML files at the end.a
object and find all instances of b
and c
. Then marshal all b
s and c
s spereratly and use XInclude to reference the resulting files. This seems inapproprite, because I don't want my storage mechanism to know all the internals of all classes. I just want to store my a
and JAXB marshalling shall handle storing the dependencies on its own as far as possible.The following questions are related to this question, in the point that they want to produce multiple XML files. But none of them considers the information given in the XSD-files and XJC-binding-files and thus require manipulation of the generated java code, some non-trivial programming overhead and some sort of information duplication.
Upvotes: 3
Views: 937
Reputation: 149057
@XmlID
& @XmlIDREF
is to facilitate references within a single XML document.
If you have a model generated from multiple XML schemas into multiple packages then you need to make sure the JAXBContext
is created to be aware of all these classes. One way to do this is creating the JAXBContext
on a colon delimited String
of package names.
JAXBContext.newInstance("com.example.pkg1:com.example.pkg2:com.example.pkg3");
Upvotes: 2