users@jaxb.java.net

Re: Class generation and <xsd:include>

From: Frank VanLoon <fvanloon_at_yahoo.com>
Date: Tue, 08 Apr 2003 08:29:06 -0600

I have tried the same solution presented to your problem.. but it did not resolve everything for me. I have a set of Common Schemas, previously using the <xs:include> tag.. I have converted those to <xs:import>, however, the <xs:import> by itself is not enough to allow the validator to find the common elements and types. I have found that, in addition to the <xs:import>, I have to add a namespace declaration at the type of the document... and use the prefix at every reference in the schema.

For example:

Common.xsd:

<xs:schema targetNamespace="http://www.me.com/common" xmlns="http://www.me.com/common" elementFormDefault="unqualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="CommonName" type="xs:string/>
</xs:schema>

and Specific.xsd:

<xs:schema targetNamespace="http://www.me.com/specific" xmlns="http://www.me.com/specific" elementFormDefault="unqualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:import namespace="http://www.me.com/common" schemaLocation="common.xsd"/>
   <xs:element name="SpecificElem">
 <xs:complexType>
  <xs:sequence>
   <xs:element ref="CommonName" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
 </xs:complexType>
   </xs:element>
</xs:schema>

 ---> This does not validate. It cannot find "CommonName" in specific.xsd.

The only way can get it to validate is to add the following attribute to the xs:schema element in specific.xsd:

xmlns:common="http://www.me.com/common"

and modify the <xs:element> tag to:

<xs:element ref="common:CommonName" minOccurs="0" maxOccurs="unbounded"/>

-- This is very undesirable for me.. is there any way to accomplish my 2 goals:
1) When generating Objects, I want each schema to create it's own package, and contain only items from that specific schema, not imported or included ones.
2) Keep my schemas clean.. with no namespace prefixes on references.

Thanks,

Frank VanLoon
fvanloon_at_yahoo.com