Re: Modelling Java Classes in XSD

Hi Andrew,

> The question is, what would be an acceptable way to mark the point where you
> want to stop modelling your object? i.e. I have the following schema:
>
> <schema xmlns='http://www.w3.org/2001/XMLSchema'
>
> targetNamespace='http://www.themindelectric.com/package/uk.co.enterpriseis.c
> ollections.base.persistent/'
>         xmlns:electric='http://www.themindelectric.com/schema/'>
>     <complexType name='Collection' abstract='true'>
>       <sequence>
>         <element name='fieldCollection' nillable='true'
> electric:field='fieldCollection'
> xmlns:ns3='http://www.themindelectric.com/package/java.util/'
> type='ns3:Collection'/>
>       </sequence>
>     </complexType>
>   </sche
> which marks "fieldCollection" as type "ns3:Collection" (effectively marking
> it as a java.util.Collection).  The problem is that if you run this through
> a schema validator (such as the one I use, the IBM Schema Quality Checker)
> it will complain as follows:
>         "Type http://www.themindelectric.com/package/java.util/:Collection is not
> found.
>         There is no import statement associated with the namespace
> 'http://www.themindel
>         ectric.com/package/java.util/'."
> and quite rightly too as the type is not found.  As I mentioned before, I
> want to mark this in some acceptable way as being a java.util.Collection
> without defining java.util.Collection in an XSD.
>
> I would appreciate any thoughts on this.

Well, if you want to use the type attribute in the XML Schema namespace then the type
you reference must exist. There's no way around that. I guess what you could do is to
use a type attribute from a different namespace to define the Java type of the
element. I guess the element that is defined to have the collections type would then
be empty because it doesn't need to carry anymore information. In that case your
schema can be:

<schema xmlns='http://www.w3.org/2001/XMLSchema'
targetNamespace='http://www.themindelectric.com/package/uk.co.enterpriseis.collections.base.persistent/'

xmlns:electric='http://www.themindelectric.com/schema/'>
   <complexType name='Collection' abstract='true'>
      <sequence>
         <element name='fieldCollection' nillable='true'
electric:field='fieldCollection'
xmlns:ns3='http://www.themindelectric.com/package/java.util/'
xs3:type='ns3:Collection'>
            <complexType/>
         </element>
      </sequence>
   </complexType>
</schema>

Would this work you think?

Cheers,
/Eddie


>
>
> Andrew Sealy-Bell.

Received on Wednesday, 3 April 2002 19:29:41 UTC