tags:

views:

349

answers:

1

I will post two examples, one that validates and one that doesn't. I am interested in learning why the second one doesn't work since they are very similar.

Example 1 (validates)

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 (does not validate)

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: (the same as 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 you the time running the diff against the xsd's, the only difference is that in the second example complex type BBB has a <choice>

xmllint says the following about Example 2:

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

example2.xml:3: element y: Schemas validity error : Element 'y': This element is not expected. Expected is ( z ).

example2.xml fails to validate


Examples loosely based off of http://www.zvon.org/xxl/XMLSchemaTutorial/Output/ser_ext_patterns_st1.html

A: 

In the xml for your invalid case, you're missing the required "z" element.

<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>

Validates on DecisionsSoft's Validator and xmlme's validator

Marc
This does not validate with xmllint either. Accepting as answer and filing a bug in xmllint https://bugzilla.gnome.org/show_bug.cgi?id=612716
leif81