Re: how to redefine a content model

Hi Francis,

Francis Brouns wrote:

>Hello,
>
>We are having problems extending a content model. We have 2 different
>schemas. In the first schema we define a content model. In the second schema
>we want to re-use the model, but add an element to it at a certain location.
>Example:
>
>In first schema the model is: test (a | c).
>In the second schema the model should become: test (a | b | c). It is
>important that element names remain identical in both schemas.
>
>How should we go about this?
>Redefining a complex type by extension only seems to allow us appending
>elements, but not inserting elements at specific locations.
>Can we redefine a group to obtain this result?
>
>Would the following be valid? In schema 1 define a group:
> <xs:group name="testGroup">
>  <xs:choice>
>   <xs:element ref="a"/>
>   <xs:element ref="c"/>
>  </xs:choice>
> </xs:group>
>
> <xs:element name="test">
>    <xs:complexType">
>       <xs:choice>
>         <xs:group ref="testGroup"/>
>       </xs:choice>
>   </xs:complexType>
> </xs:element>
>
>and in schema 2 redefine the group (and of course declare the new element)
> <xs:redefine schemaLocation="schema1.xsd">
>  <xs:group name="testGroup">
>   <xs:choice>
>    <xs:element ref="a"/>
>    <xs:element name="b"/>
>    <xs:element ref="c"/>
>   </xs:choice>
>  </xs:group>
> </xs:redefine>
>
>According to XML Spy and Turbo XML this would be valid; XSV reports errors:
>
you can use redefine to get your desired results but you can't do it in 
the way you have specified above. XML Spy and Turbo XML are incorrect in 
this case and XSV is correct (even though it should produce an error and 
not crash ;-)). This is specified in the spec at [1] in the section 
"Schema Representation Constraint: Redefinition Constraints and 
Semantics". The relevant paragraph is 6 which says:

"6 Within the [children], for each <group> the appropriate case among 
the following must be true:
   6.1 If it has a <group> among its contents at some level the ·actual 
value· of whoseref [attribute] is the same as the ·actual value· of its 
ownname attribute plus target namespace, then all of the following must 
be true:
      6.1.1 It must have exactly one such group.
      6.1.2 The ·actual value· of both that group's minOccurs 
andmaxOccurs [attribute] must be 1 (or ·absent·).
   6.2 If it has no such self-reference, then all of the following must 
be true:
      6.2.1 The ·actual value· of its own name attribute plus target 
namespace must successfully ·resolve· to a model group definition in I.
      6.2.2 The {model group} of the model group definition which 
corresponds to it per XML Representation of Model Group Definition 
Schema Components (§3.7.2) must be a ·valid restriction· of the {model 
group} of that model group definition in I, as defined in Particle Valid 
(Restriction) (§3.9.6)."

Your redefinition above is incorrect because it doesn't have a <group> 
among its contents whose ref is the same as the actual value of its own 
name so 6.1 is not true. Instead you have started of specifying 6.2 and 
6.2.1 is satisfied but the problem is with 6.2.2 which only allows you 
to specify a content model which is a *restriction* of the original 
group. In your case you have specified an extension which can't be done 
like this.
The correct way to specify an extension of a group in a redefinition is 
to use the path from 6.1 where you need a reference to the original 
group. Here is what the correct redefinition should look like (in schema2):

  <xs:redefine schemaLocation="schema1.xsd">
  <xs:group name="testGroup">
   <xs:choice>
    <xs:group ref="testGroup"/>
    <xs:element name="b"/>
   </xs:choice>
  </xs:group>
 </xs:redefine>

Cheers,
/Eddie

[1] http://www.w3.org/TR/xmlschema-1/#modify-schema

>
><schemaDocAttempt URI='file:/D:/schema2.xsd' outcome='success'
>source='redefine'/>
><bug>validator crash during command line:
>Traceback (most recent call last):
>  File "d:\work\XMLinter\fschema\XMLSchemaCore.py", line 468, in
>checkinSchema
>  File "d:\work\XMLinter\fschema\XMLSchemaCore.py", line 250, in fromFile
>  File "d:\work\XMLinter\fschema\layer.py", line 275, in fromFile
>  File "d:\work\XMLinter\fschema\layer.py", line 359, in processElement
>  File "d:\work\XMLinter\fschema\layer.py", line 396, in processElement
>  File "d:\work\XMLinter\fschema\XMLSchemaElt.py", line 712, in init
>AttributeError: 'Choice' instance has no attribute 'redefine'
></bug>
>
>Any pointers would be welcome.
>
>Thanks.
>
>Francis Brouns
>
>  
>

Received on Monday, 28 October 2002 19:31:51 UTC