You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-dev@xml.apache.org by David Waite <ma...@akuma.org> on 2004/04/07 20:39:26 UTC

Substitution group issues

I posted a bug a while back regarding substitution groups; I have not 
followed up on this bug since several deeper problems have shown 
themselves since that original bug/fix.

I ask now; how are substitution groups expected to work within 
XMLBeans? Given the following example

ns1:Foo is of type ns1:FooType, which contains an element reference to 
ns1:Bar, which is of ns1:BarType.

ns2:Foo is of type ns2:FooType, where ns2:FooType is an extension of 
ns1:FooType and is in the substitution group for ns1:Foo
ns2:FooType extends ns1:FooType. ns2:Bar, which is of ns2:BarType, is 
in the substututiongroup for ns1:Bar.

or, in schema form:

<xs:schema targetNamespace="urn:fizzle"
     xmlns='urn:fizzle'
     elementFormDefault="qualified"
     version="1.0"
     xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name='Foo' type='FooType'/>
  <xs:element name='Bar' type='BarType'/>
  <xs:complexType name="FooType">
   <xs:sequence>
    <xs:element ref='Bar' minOccurs='0'/>
   </xs:sequence>
  </xs:complexType>
  <xs:complexType name="BarType">
    <xs:sequence>
     <xs:any/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

------

<xs:schema targetNamespace="urn:fizzle2"
     xmlns='urn:fizzle2'
     xmlns:ns1='urn:fizzle'
     elementFormDefault="qualified"
     version="1.0"
     xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import namespace='urn:fizzle' schemaLocation='schema.xsd'/>
  <xs:element name='Foo' type='FooType' substitutionGroup='ns1:Foo'/>
  <xs:element name='Bar' type='BarType' substitutionGroup='ns1:Bar'/>
  <xs:complexType name="FooType">
   <xs:complexContent>
   <xs:extension base='ns1:FooType'>
    <xs:attribute name='dummy' type='xs:string'/>
   </xs:extension>
   </xs:complexContent>
  </xs:complexType>
  <xs:complexType name="BarType">
   <xs:complexContent>
   <xs:extension base='ns1:BarType'>
     <xs:attribute name='dummy' type='xs:string'/>
   </xs:extension>
   </xs:complexContent>
  </xs:complexType>
</xs:schema>

First, compilation of these schemas into classes fails because the 
documents inherit from one another, but Java < 1.5 does not support 
covariant return types - getFoo() and getBar() are the same methods 
with more specific return types. Perhaps the document types should not 
be subclassed - it is handy to be able to represent and pass along a 
document and subtyped documents into functions, but acceptable to 
loosen type and pass XmlObject around.

Secondly, would there be a way to control when a <foo> element has an 
element added of type ns2:BarType, whether it is represented as 
<ns2:Bar>, or a xsi:typed <ns1:Bar> ? I would assume that since 
substitution groups are 'syntactic sugar' which does not affect the 
meaning of the document, this would be some form of XmlOption.

Lastly, do substitution groups work if the second schema is in a 
separate jarfile? I notice that the SchemaProperty class has an 
accessor for 'acceptedNames'; is this a list of acceptable qnames for 
this element according to substitution groups? If so and if a second 
schema is loaded later, will these SchemaProperty classes get 
regenerated (since they are set immutable), or will you just not be 
able to use these elements with substitution groups?

-David Waite