users@jaxb.java.net

schema and namespace

From: Brian Matzon <brian_at_matzon.dk>
Date: Wed, 17 Dec 2008 14:56:28 +0100

Hi

I am trying to generate a schema for multiple un-annotated classes, some of
which have the same name, but in different packages.
I tried working with package-info, but for some reason that didn't work at
all (as if jaxb didn't even see the classes? - regardless, I can use it
since its 1.6).

src:
  com.example.p1.TObject.java
  com.example.p1.TPerson.java (extends com.example.p1.TObject)
  com.example.p2.TObject.java

test:
  JAXBContext context = JAXBContext.newInstance(info);
  context.generateSchema(new MySchemaOutputResolver());

where "info" is an array of classes (the above) - Error:
        this problem is related to the following location:
                at com.example.p1.TObject
        this problem is related to the following location:
                at com.example.p2.TObject

How can I make JAXB output multiple namespaces in the same schema file?
Or even better one schema file per namespace?

Basically, something like this:
<xs:schema version="1.0" targetNamespace="http://p1.example.com"
xmlns:tns="http://p1.example.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
  
  <xs:import namespace="http://p2.example.com"
schemaLocation="schema2.xsd"/>

  <xs:complexType name="tObject">
    <xs:sequence>
      <xs:element name="objName" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="tPerson">
    <xs:complexContent>
      <xs:extension base="tns:tObject">
        <xs:sequence>
          <xs:element name="name" type="xs:string" minOccurs="0"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

</xs:schema>

where 'schema2.xsd' would be something like this:
<xs:schema version="1.0" targetNamespace="http://p2.example.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="tObject">
    <xs:sequence>
      <xs:element name="id" type="xs:int"/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>