XSD validation issue with select and extension elements

I will post two examples, one of which checks and the other does not. I am interested to know why the second does not work, as they are very similar.

Example 1 (verifies)

XSD:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
  <xsd:element name="root" type="BBB"/>
    <xsd:complexType name="AAA">
      <xsd:choice maxOccurs="2">
        <xsd:element name="x" type="xsd:string"/>
        <xsd:element name="y" type="xsd:string"/>
      </xsd:choice>
    </xsd:complexType>
  <xsd:complexType name="BBB">
    <xsd:complexContent>
      <xsd:extension base="AAA"/>
    </xsd:complexContent>
  </xsd:complexType>
</xsd:schema>

XML:

<root xsi:noNamespaceSchemaLocation="incorrect.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
   <x>1</x>
   <y>1</y>
</root>

Example 2 (not verified)

XSD:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
   <xsd:element name="root" type="BBB"/>
   <xsd:complexType name="AAA">
      <xsd:choice maxOccurs="2">
         <xsd:element name="x" type="xsd:string"/>
         <xsd:element name="y" type="xsd:string"/>
      </xsd:choice>
   </xsd:complexType>
   <xsd:complexType name="BBB">
      <xsd:complexContent>
         <xsd:extension base="AAA">
            <xsd:choice>
               <xsd:element name="z" type="xsd:string"/>
            </xsd:choice>
         </xsd:extension>
      </xsd:complexContent>
   </xsd:complexType>
</xsd:schema>

xml: (same as in example 1)

<root xsi:noNamespaceSchemaLocation="incorrect.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
   <x>1</x>
   <y>1</y>
</root>

To save time running diff against xsd, the only difference is that in the second example, the complex BBB type has <choice>

xmllint says the following about example 2:

$ xmllint --noout --schema example2.xsd example2.xml

example2.xml: 3: element y: schema valid error: element 'y': this element is not expected. Expected (z).

example2.xml cannot be verified


, http://www.zvon.org/xxl/XMLSchemaTutorial/Output/ser_ext_patterns_st1.html

+3
1

xml "z".

<root xsi:noNamespaceSchemaLocation="incorrect.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
   <x>1</x>
   <y>1</y>
   <z>1</z>
</root>

DecisionsSoft Validator xmlme validator

+1

Source: https://habr.com/ru/post/1736687/


All Articles