Re: Xerces developers - there's a bug in Xerces schema validation

Well, in general Xerces is right, according with the 1.0 spec, which 
defines the algorithm as a normative reference.

Basically, according to 2.1 of
https://www.w3.org/TR/xmlschema-1/#cos-particle-restrict
Any top-level element declaration particle (in R or B) which is the 
{substitution group affiliation} of one or more other element 
declarations and whose ·substitution group· contains at least one 
element declaration other than itself is treated as if it were a choice 
group whose {min occurs} and {max occurs} are those of the particle, and 
whose {particles} consists of one particle with {min occurs} and {max 
occurs} of 1 for each of the declarations in its ·substitution group·.

the algorithm will try to align

             <xs:choice minOccurs="0" maxOccurs="unbounded">
                 <xs:element ref="A" minOccurs="1" maxOccurs="1"/>
                 <xs:element ref="B" minOccurs="1" maxOccurs="1"/>
             </xs:choice>

as base, against

             <xs:element ref="B" minOccurs="0" />

as derived.

Having an element in the derived and a choice in the base will get us to 
follow the rule
https://www.w3.org/TR/xmlschema-1/#rcase-RecurseAsIfGroup

which will check

             <xs:choice minOccurs="0" maxOccurs="unbounded">
                 <xs:element ref="A" minOccurs="1" maxOccurs="1"/>
                 <xs:element ref="B" minOccurs="1" maxOccurs="1"/>
             </xs:choice>
as base, against
             <xs:choice minOccurs="1" maxOccurs="1">
                 <xs:element ref="B" minOccurs="0" />
             </xs:choice>
as derived, according to
***
For an element declaration particle to be a ·valid restriction· of a 
group particle (all, choice or sequence) a group particle of the variety 
corresponding to B's, with {min occurs} and {max occurs} of 1 and with 
{particles} consisting of a single particle the same as the element 
declaration must be a ·valid restriction· of the group as defined by 
Particle Derivation OK, (All:All,Sequence:Sequence -- Recurse) (§3.9.6), 
Particle Derivation OK (Choice:Choice -- RecurseLax) (§3.9.6) or 
Particle Derivation OK (All:All,Sequence:Sequence -- Recurse) (§3.9.6), 
depending on whether the group is all, choice or sequence.
***

Which will get us to
https://www.w3.org/TR/xmlschema-1/#rcase-RecurseLax
where the occurrence range is ok, but we need to check
***
2 There is a complete ·order-preserving· functional mapping from the 
particles in the {particles} of R to the particles in the {particles} of 
B such that each particle in the {particles} of R is a ·valid 
restriction· of the particle in the {particles} of B it maps to as 
defined by Particle Valid (Restriction) (§3.9.6).
***

for
                 <xs:element ref="A" minOccurs="1" maxOccurs="1"/>
                 <xs:element ref="B" minOccurs="1" maxOccurs="1"/>

against the derived

                 <xs:element ref="B" minOccurs="0" />

and we cannot find that as the range check of the reference to B in the 
base type will not include the range specified in the reference to B in 
the derived type.

So, it looks like Xerces is right to report an error and it points 
exactly to point 2 from the above rule
https://www.w3.org/TR/xmlschema-1/#rcase-RecurseLax

but of course that is not intuitive, but it is the conformant behavior 
according to the 1.0 spec.

You can see also now that if you put minOccurs="1" on B in the derived type:

<xs:element ref="B" minOccurs="1" />

then that will match against the (1:1) occurrence in the base and that 
is why you do not get an error in that case.

Hope this helps!

Best Regards,
George
--
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

On 25/02/16 19:01, Costello, Roger L. wrote:
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"  vc:minVersion="1.1">
>
>       <xs:element name="A" type="xs:double" />
>       <xs:element name="B" substitutionGroup="A" type="xs:double" />
>
>       <xs:complexType name="base">
>           <xs:sequence>
>               <xs:element ref="A" minOccurs="0" maxOccurs="unbounded" />
>           </xs:sequence>
>       </xs:complexType>
>
>       <xs:complexType name="derived">
>           <xs:complexContent>
>               <xs:restriction base="base">
>                   <xs:sequence>
>                       <xs:element ref="B" minOccurs="0" />
>                   </xs:sequence>
>               </xs:restriction>
>           </xs:complexContent>
>       </xs:complexType>
> </xs:schema>

Received on Thursday, 25 February 2016 18:15:56 UTC