元素{element}的类型定义无法从其替换组affiliation {element}的类型定义中有效地派生

时间:2014-08-12 06:21:18

标签: xml validation xsd schema xsd-validation

我一直在处理一个问题,虽然看起来相对简单,但我花了很多时间却没有成功。我正在创建一个地理标记语言(GML)的配置文件,类似于CityGML。但是,我一直得到错误“元素{element}的类型定义不能从其替换组affiliation {element}的类型定义中有效地派生出来”尽管事实上我的一切看起来都很好。

我设计模式的方式,在“Flood.xsd”中,我应该可以使用“_floodObject”代替“_urbanObject”。但是,当我尝试验证我的“flood.xsd”架构时,我收到错误: “元素'_FloodObject'的类型定义不能有效地从其替换组从属关系'_UrbanObject'中获得。”

你能指导我在这里做错了什么吗? 非常感谢并期待收到意见以解决问题。

萨姆

My Root(我称之为CORE)架构如下:

<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">
  <xs:annotation>
    <xs:documentation />
  </xs:annotation>
  <xs:import namespace="http://www.opengis.net/gml/3.2" 
    schemaLocation="http://schemas.opengis.net/gml/3.2.1/gml.xsd"/>
  <xs:import namespace="http://localhost/schemas/Material/1.0" 
    schemaLocation="http://localhost/Schemas/Schema/MaterialDomain.xsd"/>

    <!-- ======================UrbanFloodModel (root element) =========================================== -->
  <xs:element name="UrbanFloodModel" 
    type="UrbanFloodModelType" 
    substitutionGroup="gml:AbstractFeatureCollection"/>
  <!-- ======================UrbanFloodModelType=========================================== -->
  <xs:complexType name="UrbanFloodModelType">
    <xs:complexContent>
      <xs:extension base="gml:AbstractFeatureCollectionType">
        <xs:sequence>
          <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="MaterialObjectMember" 
                        type="mtl:MaterialObjectMemberType"/>
            <xs:element name="UrbanObjectMember" 
                        type="UrbanObjectMemberType"/>
            <xs:element name="SpatialStructureObjectMember" 
                        type="SpatialStructureObjectMemberType"/>
          </xs:choice>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <!-- ======================UrbanObjectMemberType=========================================== -->
  <xs:complexType name="UrbanObjectMemberType">
    <xs:sequence>
      <xs:element ref="_UrbanObject" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>
  <!-- ======================_UrbanObject=================================================== -->
  <xs:element name="_UrbanObject" 
              abstract="true" 
              type="AbstractUrbanObjectType" 
              substitutionGroup="gml:AbstractFeature" />
  <!-- ======================AbstractUrbanObjectType======================================== -->
  <xs:complexType name="AbstractUrbanObjectType" abstract="true">
    <xs:annotation>
      <xs:documentation>Type describing the abstract superclass of urban objects.</xs:documentation>
    </xs:annotation>
    <xs:complexContent>
      <xs:extension base="gml:AbstractFeatureType">
        <xs:sequence>
          <xs:element name="ContainedInSpatialStructures">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="SpatialStructureObjectReference" 
                            type="xs:string" 
                            maxOccurs="unbounded"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <!-- ======================SpatialStructureObjectMemberType======================================== -->
  <xs:complexType name="SpatialStructureObjectMemberType">
    <xs:annotation>
      <xs:documentation>Type describing the abstract superclass of urban objects.</xs:documentation>
    </xs:annotation>
    <xs:complexContent>
      <xs:extension base="gml:AbstractFeatureType">
        <xs:sequence>
          <xs:element name="ContainedUrbanObjects" minOccurs="0">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="UrbanObjectReference" 
                            type="xs:string" 
                            minOccurs="1" 
                            maxOccurs="unbounded"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
        <xs:attribute name="referenceSpatialStructureElementID" 
                      type="xs:string" 
                      use="required"/>
        <xs:attribute name="spatialStructureElementType" 
                      type="xs:int" 
                      use="required"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>

和我的“Flood.xsd”(将上述架构导入为“核心”)如下所示:

<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">
    <xs:import namespace="http://www.opengis.net/gml/3.2" 
      schemaLocation="http://schemas.opengis.net/gml/3.2.1/gml.xsd"/>
    <xs:import namespace="http://localhost/schemas/1.0" 
      schemaLocation="http://localhost/Schemas/Schema/UrbanFloodBase.xsd"/>

  <!-- ==================================FloodObject======================================== -->
  <xs:element name="_FloodObject" 
              type="AbstractFloodObjectType" 
              abstract="true" 
              substitutionGroup="core:_UrbanObject"/>

  <xs:complexType name="AbstractFloodObjectType">
    <xs:annotation/>
    <xs:complexContent>
      <xs:extension base="core:AbstractUrbanObjectType"/>
    </xs:complexContent>
  </xs:complexType> 
</xs:schema>

1 个答案:

答案 0 :(得分:1)

它不会让我看起来好像你做错了什么。 Saxon和Xerces都告诉我架构文档是有效的(尽管Saxon确实警告GML架构文档递归地包含它们。)

您使用的是什么XSD验证器?