title: Reuse JAXB classes for similar schemas
body: <p>I have two similar schemas which have, for some elements, identical structure, but are defined under different namespaces. Is there any way to reuse the JAXB generated classes for the first schema when generating classes for the second schema? I know jaxb allows for binding customization, but I haven't been able to find out whether the same set of classes can be used <strong>simultaneously</strong> with two namespaces. More specifically:</p>
  
  <p>Schema1</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;xs:schema xmlns="ns1" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="ns1"&gt;
      &lt;xs:element name="Document" type="Document"/&gt;
      &lt;xs:complexType name="Document"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="Root1" type="Root1Type"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:complexType name="Root1Type"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="Child" type="ChildType"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:complexType name="ChildType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element maxOccurs="1" minOccurs="0" name="MndtId" type="Max35Text"/&gt;
              &lt;xs:element name="MndtReqId" type="Max35Text"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:simpleType name="Max35Text"&gt;
          &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:minLength value="1"/&gt;
              &lt;xs:maxLength value="35"/&gt;
          &lt;/xs:restriction&gt;
      &lt;/xs:simpleType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Schema2</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;xs:schema xmlns="ns2" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="ns2"&gt;
      &lt;xs:element name="Document" type="Document"/&gt;
      &lt;xs:complexType name="Document"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="Root2" type="Root2Type"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:complexType name="Root2Type"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="Child" type="ChildType"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:complexType name="ChildType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element maxOccurs="1" minOccurs="0" name="MndtId" type="Max35Text"/&gt;
              &lt;xs:element name="MndtReqId" type="Max35Text"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:simpleType name="Max35Text"&gt;
          &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:minLength value="1"/&gt;
              &lt;xs:maxLength value="35"/&gt;
          &lt;/xs:restriction&gt;
      &lt;/xs:simpleType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>xjc will generate for the first schema:</p>
  
  <pre><code>ns1/ChildType.java
  ns1/Document.java
  ns1/ObjectFactory.java
  ns1/Root1Type.java
  ns1/package-info.java
  </code></pre>
  
  <p>and for the second:</p>
  
  <pre><code>ns2/ChildType.java
  ns2/Document.java
  ns2/ObjectFactory.java
  ns2/Root2Type.java
  ns2/package-info.java
  </code></pre>
  
  <p>What I would like to know is whether I can reuse ChildType generated for the first schema when generating classes for the second schema.</p>
  
  <p>Thanks</p>