Can we generate JAXB classes for xsd in multiple packages?

I have xsd that has several child XSD s (using "xsd: include".) In it (but each xsd belongs to the same namespace ). I was asked to generate jaxb classes in separate subpackages (one additional package for each child XSD) instead of one package.

According to what I have read so far, we can add jaxb:schemaBindings to these individual xsds and generate classes in separate packages, provided that those xsds belong to different namespaces .

But in my case, what I want to do is create classes in several subpackages for a set of xsds belonging to the same namespace . Could you help me do this with JAXB?

<h / "> Edit: I added some details about my problem to clarify this a bit.

All of my XSDs have the following header. Therefore the 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"> 

Say my schema file names are A.xsd, B.xsd, and C.xsd.

  • In C.xsd, I defined some elements (string type) with the above header.

  • In B.xsd, I included C.xsd using the tag "xsd: include", then there is a definition for complexType using the complex types defined in C.xsd. (It has the same title that I mentioned above)

  • In A.xsd, I included B.xsd using the tag "xsd: include", then there is a definition for complexType using the complex types defined in B.xsd. (It has the same title that I mentioned above)

I want to create JAXB classes, as I mentioned below.

  • JAXB classes associated with A.xsd for generation in the package com.generate.packageA.

  • JAXB classes related to B.xsd for generation in package com.generate.packageB.

  • JAXB classes associated with C.xsd to be generated in the com.generate.packageC package.

+4
source share
1 answer

You can create JAXB classes from each of the β€œincluded” schemas separately in separate packages and use the episode engine available in the XJC tool.

Examples (from stack overflow responses)

+2
source

Source: https://habr.com/ru/post/1446910/


All Articles