Waog
Waog

Reputation: 7275

Store JAXB-Objects into multiple XML files

Situation

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.

Problem

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?

Approaches

I have the following approaches at hand, but they are not sutable:

Comparable Questions and Anwsers

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

Answers (1)

bdoughan
bdoughan

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

Related Questions