Why did this XDocument fail validation?

Given the scheme (anonymous, the key points of interest are renamed, and the rest are omitted):

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="inspec"
    targetNamespace="the_right_namespace"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xs:element name="inspec">
    <xs:complexType>
      <xs:all>
        <xs:element name="a_scalar_property" type="xs:int"/>
        <xs:element name="a_collection_property">
          <xs:complexType>
            <snip>
          </xs:complexType>
        </xs:element>
        <xs:element name="another_collection_property">
          <xs:complexType>                
            <snip>
          </xs:complexType>
        </xs:element>                       
      </xs:all>
    </xs:complexType>
  </xs:element>
</xs:schema>

and instance (declared using VB xml literals):

Dim xDocument = 
<x:inspec xmlns:x='the_right_namespace'>
<a_collection_property/>
<another_collection_property/>
</x:inspec>

verification ends with a message The element 'inspec' in namespace 'the_right_namespace' has incomplete content. List of possible elements expected: 'a_scalar_property'.

Why? Element allaccording to W3Schools:

"The whole element indicates that the children can be displayed in any order and that each child can be zero or one time."

Lowering a_scalar_propertyis the same as its zero time. Why is this document not checked?

And don't say things like “publish full code” - this is not my IP address, and I anonymized it for a good reason. This is very small, and I checked this minimal example, it gives the same result.

+5
source
2

minOccurs="0" xs:all:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="inspec"
    targetNamespace="the_right_namespace"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
    <xs:element name="inspec">
        <xs:complexType>
            <xs:all>
                <xs:element name="a_scalar_property" type="xs:int" minOccurs="0" />
                <xs:element name="a_collection_property" minOccurs="0">
                    <xs:complexType>
                        <!-- snip -->
                    </xs:complexType>
                </xs:element>
                <xs:element name="another_collection_property" minOccurs="0">
                    <xs:complexType>
                        <!-- snip -->
                    </xs:complexType>
                </xs:element>
            </xs:all>
        </xs:complexType>
    </xs:element>
</xs:schema>
+6

, minOccurrs 0, <all> . XML , w3schools .

+2

All Articles