Reputation: 5091
I have an xsd which has several child XSD s embedded (using "xsd:include".) in it (but each xsd belongs to the same namespace). I was asked to generate jaxb classes in separate sub packages (one sub package per each child XSD) instead of one package.
According to what I have read so far, we can add jaxb:schemaBindings
to these separate xsds and generate the classes in separate packages, if only those xsds belong to different namespaces.
But in my case, what I want to do is to create classes in several sub packages for a set of xsds belong to the same namespace. Could you please help me to do this using JAXB?
All of my XSDs has following header. Therefore same namespace.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:srm="http://www.mycompany.com/srm/"
targetNamespace="http://www.mycompany.com/srm/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0" elementFormDefault="qualified"
attributeFormDefault="unqualified" version="1.0">
Let's say my schema file names are A.xsd, B.xsd, and C.xsd.
In C.xsd, I have defined some elements (string type) with above mentioned header.
In B.xsd, I have included C.xsd using "xsd:include" tag, then there is a complexType definition using the complex types defined in C.xsd.(Has the same header I have mentioned above)
In A.xsd, I have included B.xsd using "xsd:include" tag, then there is a complexType definition using the complex types defined in B.xsd.(Has the same header I have mentioned above)
I want to generate JAXB classes like I have mentioned below.
The JAXB classes related to A.xsd to generate in com.generate.packageA package.
The JAXB classes related to B.xsd to generate in com.generate.packageB package.
The JAXB classes related to C.xsd to generate in com.generate.packageC package.
Upvotes: 5
Views: 6585
Reputation: 148977
You could generate JAXB classes from each of the "included" schemas separately into separate packages and leverage the episode mechanism available in the XJC tool.
Examples (from answers given on Stack Overflow)
Upvotes: 3