1

I have a couple of comprehensive XSDs which inlcude the same complexType definition for the same member. Each XSD has its own namespace. So when I run xjc on the xsds, I get the same complexType class generated in each namespace.

This ends up being extremely confusing and complicated to handle. I would like to create a binding that tells XJC not to generate the complexType for one of the XSDs and rather to use the class already generated by the other xsd.

I've tried the following without success:

   <jaxb:bindings schemaLocation="../xsd/sandboxlist.xsd">
        <jaxb:bindings node="/xsd:schema">
            <jaxb:schemaBindings>
                <jaxb:package name="com.domain.schema.model.v4_0.sandboxlist"/>
            </jaxb:schemaBindings>
        </jaxb:bindings>
        <jaxb:bindings node="//xsd:complexType[@name='SandboxType']">
            <jaxb:class name="com.domain.schema.model.v4_0.sandboxinfo.SandboxType" />
        </jaxb:bindings>
    </jaxb:bindings>

I am looking to tell XJC that SandboxType in sandboxlist.xsd should actually be class com.domain.schema.model.v4_0.sandboxinfo.SandboxType (coming from a different XSD).

What is the proper syntax for this?

Eric B.
  • 23,425
  • 50
  • 169
  • 316

1 Answers1

1

You can achieve this via jaxb:class/@ref:

<jaxb:class ref="com.domain.schema.model.v4_0.sandboxinfo.SandboxType" />

But, better, use episodes. Generate using -episode CLI parameter and then add your JAR to the xjc command line.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • Thanks! I had finally stumbled upon the ref attribute accidentally in another post. It's a shame that the bindings file isn't better documented anywhere (or at least that I could find easily!). But I am interested by `episodes` and will dig into that further. The problem I am having, however, is that SandboxType is defined in both XSDs and as such, from my quick understanding, I don't think that episodes would help. Please correct me if my understanding is wrong. – Eric B. Sep 24 '15 at 19:06
  • Here's more on episodes: http://stackoverflow.com/questions/9756185/what-is-an-episode-file – lexicore Sep 24 '15 at 19:13
  • If your type is defined in two schemas, then no, episodes won't help much. But I don't think you'll be able to bind two complex types from different onto the same class. I guess there will be namespace conflicts. – lexicore Sep 24 '15 at 19:15