title: type definition of element {element} is not validly derived from that of its substitution group affiliation {element}
body: <p>I have been dealing with a problem that although seems to be relatively simple, been taking a lot of my time with no success. I am creating a profile of Geographic Markup Language (GML), similar to CityGML. However, I keep getting the error "type definition of element {element} is not validly derived from that of its substitution group affiliation {element}" despite the fact to me everything looks ok with the schemas.</p>
  
  <p>The way I designed the schemas, in the "Flood.xsd", I should be able to use"_floodObject" as a substitute of "_urbanObject". However I get the error when I try to validate my "flood.xsd" schema:
  "The type definition of element '_FloodObject' is not validly derived from that of its substitution group affiliation '_UrbanObject'."</p>
  
  <p>Can you guide me what I'm doing wrong here? 
  Many thanks and looking forward to receiving comments to resolve the issue.</p>
  
  <p>Sam</p>
  
  <p>My Root ( i call it CORE) schema is as follows:</p>
  
  <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:gml="http://www.opengis.net/gml/3.2" 
    xmlns="http://localhost/schemas/1.0" 
    xmlns:mtl="http://localhost/schemas/Material/1.0" 
    targetNamespace="http://localhost/schemas/1.0" 
    elementFormDefault="qualified" 
    attributeFormDefault="unqualified" 
    version="1.0"&gt;
    &lt;xs:annotation&gt;
      &lt;xs:documentation /&gt;
    &lt;/xs:annotation&gt;
    &lt;xs:import namespace="http://www.opengis.net/gml/3.2" 
      schemaLocation="http://schemas.opengis.net/gml/3.2.1/gml.xsd"/&gt;
    &lt;xs:import namespace="http://localhost/schemas/Material/1.0" 
      schemaLocation="http://localhost/Schemas/Schema/MaterialDomain.xsd"/&gt;
  
      &lt;!-- ======================UrbanFloodModel (root element) =========================================== --&gt;
    &lt;xs:element name="UrbanFloodModel" 
      type="UrbanFloodModelType" 
      substitutionGroup="gml:AbstractFeatureCollection"/&gt;
    &lt;!-- ======================UrbanFloodModelType=========================================== --&gt;
    &lt;xs:complexType name="UrbanFloodModelType"&gt;
      &lt;xs:complexContent&gt;
        &lt;xs:extension base="gml:AbstractFeatureCollectionType"&gt;
          &lt;xs:sequence&gt;
            &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;
              &lt;xs:element name="MaterialObjectMember" 
                          type="mtl:MaterialObjectMemberType"/&gt;
              &lt;xs:element name="UrbanObjectMember" 
                          type="UrbanObjectMemberType"/&gt;
              &lt;xs:element name="SpatialStructureObjectMember" 
                          type="SpatialStructureObjectMemberType"/&gt;
            &lt;/xs:choice&gt;
          &lt;/xs:sequence&gt;
        &lt;/xs:extension&gt;
      &lt;/xs:complexContent&gt;
    &lt;/xs:complexType&gt;
    &lt;!-- ======================UrbanObjectMemberType=========================================== --&gt;
    &lt;xs:complexType name="UrbanObjectMemberType"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element ref="_UrbanObject" minOccurs="0" /&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
    &lt;!-- ======================_UrbanObject=================================================== --&gt;
    &lt;xs:element name="_UrbanObject" 
                abstract="true" 
                type="AbstractUrbanObjectType" 
                substitutionGroup="gml:AbstractFeature" /&gt;
    &lt;!-- ======================AbstractUrbanObjectType======================================== --&gt;
    &lt;xs:complexType name="AbstractUrbanObjectType" abstract="true"&gt;
      &lt;xs:annotation&gt;
        &lt;xs:documentation&gt;Type describing the abstract superclass of urban objects.&lt;/xs:documentation&gt;
      &lt;/xs:annotation&gt;
      &lt;xs:complexContent&gt;
        &lt;xs:extension base="gml:AbstractFeatureType"&gt;
          &lt;xs:sequence&gt;
            &lt;xs:element name="ContainedInSpatialStructures"&gt;
              &lt;xs:complexType&gt;
                &lt;xs:sequence&gt;
                  &lt;xs:element name="SpatialStructureObjectReference" 
                              type="xs:string" 
                              maxOccurs="unbounded"/&gt;
                &lt;/xs:sequence&gt;
              &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
        &lt;/xs:extension&gt;
      &lt;/xs:complexContent&gt;
    &lt;/xs:complexType&gt;
    &lt;!-- ======================SpatialStructureObjectMemberType======================================== --&gt;
    &lt;xs:complexType name="SpatialStructureObjectMemberType"&gt;
      &lt;xs:annotation&gt;
        &lt;xs:documentation&gt;Type describing the abstract superclass of urban objects.&lt;/xs:documentation&gt;
      &lt;/xs:annotation&gt;
      &lt;xs:complexContent&gt;
        &lt;xs:extension base="gml:AbstractFeatureType"&gt;
          &lt;xs:sequence&gt;
            &lt;xs:element name="ContainedUrbanObjects" minOccurs="0"&gt;
              &lt;xs:complexType&gt;
                &lt;xs:sequence&gt;
                  &lt;xs:element name="UrbanObjectReference" 
                              type="xs:string" 
                              minOccurs="1" 
                              maxOccurs="unbounded"/&gt;
                &lt;/xs:sequence&gt;
              &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
          &lt;xs:attribute name="referenceSpatialStructureElementID" 
                        type="xs:string" 
                        use="required"/&gt;
          &lt;xs:attribute name="spatialStructureElementType" 
                        type="xs:int" 
                        use="required"/&gt;
        &lt;/xs:extension&gt;
      &lt;/xs:complexContent&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>and my "Flood.xsd" (importing the above schema as "core") looks like this:</p>
  
  <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:gml="http://www.opengis.net/gml/3.2" 
    xmlns:core="http://localhost/schemas/1.0" 
    xmlns="http://localhost/schemas/Flood/1.0" 
    targetNamespace="http://localhost/schemas/Flood/1.0" 
    elementFormDefault="qualified" version="1.0"&gt;
      &lt;xs:import namespace="http://www.opengis.net/gml/3.2" 
        schemaLocation="http://schemas.opengis.net/gml/3.2.1/gml.xsd"/&gt;
      &lt;xs:import namespace="http://localhost/schemas/1.0" 
        schemaLocation="http://localhost/Schemas/Schema/UrbanFloodBase.xsd"/&gt;
  
    &lt;!-- ==================================FloodObject======================================== --&gt;
    &lt;xs:element name="_FloodObject" 
                type="AbstractFloodObjectType" 
                abstract="true" 
                substitutionGroup="core:_UrbanObject"/&gt;
  
    &lt;xs:complexType name="AbstractFloodObjectType"&gt;
      &lt;xs:annotation/&gt;
      &lt;xs:complexContent&gt;
        &lt;xs:extension base="core:AbstractUrbanObjectType"/&gt;
      &lt;/xs:complexContent&gt;
    &lt;/xs:complexType&gt; 
  &lt;/xs:schema&gt;
  </code></pre>