【问题标题】:XSD Error: Type is not declared, or is not a simple typeXSD 错误:类型未声明,或者不是简单类型
【发布时间】:2016-08-06 16:22:06
【问题描述】:

为了这个解释,我使用了 2 个不同的 XSD:

customEntry.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="customEntry"
    targetNamespace="http://tempuri.org/customEntry.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/customEntry.xsd"
    xmlns:mstns="http://tempuri.org/customEntry.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"        
    >
  <xs:simpleType name="customEntry">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Za-z0-9_%./]*"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

element_ArtStyleSuffix.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="element_ArtStyleSuffix"
    targetNamespace="http://tempuri.org/element_ArtStyleSuffix.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/element_ArtStyleSuffix.xsd"
    xmlns:mstns="http://tempuri.org/element_ArtStyleSuffix.xsd"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
    >
  <xs:import namespace="http://tempuri.org/customEntry.xsd" schemaLocation="customEntry.xsd"/>

  <!-- Civilizations ArtStyleSuffix Enumeration -->
  <xs:simpleType name="enum_ArtStyleSuffix">
    <xs:restriction base="xs:string">
      <xs:enumeration value="_EURO"/>
      <xs:enumeration value="_AFRI"/>
      <xs:enumeration value="_AMER"/>
      <xs:enumeration value="_ASIA"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- ArtStyleSuffix GameData Schema Information -->
  <xs:element name="GameData">
    <xs:complexType>
      <xs:all>
        <xs:element minOccurs="0" maxOccurs="1" name="ArtStyleSuffix">
          <xs:annotation>
            <xs:documentation>
              Select a default ArtStyleSuffix or you may create your own custom one and place its TypeName here.
            </xs:documentation>
          </xs:annotation>
          <xs:simpleType>
            <xs:union memberTypes="customEntry enum_ArtStyleSuffix"/>
          </xs:simpleType>
        </xs:element>
      </xs:all>
    </xs:complexType>
  </xs:element>
</xs:schema>

我的问题在于以下行:

<xs:union memberTypes="customEntry enum_ArtStyleSuffix"/>

Visual Studio 2015 社区正在抛出错误:

键入“http://tempuri.org/element_ArtStyleSuffix.xsd:customEntry是 未声明,或者不是简单类型

对我来说它看起来像一个简单的类型,我认为导入行声明了它,所以也许我不完全理解“导入”,因为我没有从导入行收到任何错误,只是联合行。我这样做对吗?

【问题讨论】:

    标签: xml xsd xsd-validation xml-validation


    【解决方案1】:

    确实是简单的类型。但是,它并没有在当前 XSD 的目标命名空间中声明;它在导入的 XSD 的命名空间中声明。在导入的http://tempuri.org/customEntry.xsd 命名空间中引用customEntry 以消除错误...

    具体来说,在主 XSD 的 xs:schema 元素上声明命名空间前缀:

    xmlns:ce="http://tempuri.org/customEntry.xsd"
    

    以便您可以在 xs:union 声明中使用它:

    <xs:union memberTypes="ce:customEntry enum_ArtStyleSuffix"/>
    

    你的错误就会消失。

    旁注:可以接受,但既不需要也不需要将命名空间命名为 XSD 文件的 URL;考虑删除.xsd 扩展。

    【讨论】:

      猜你喜欢
      • 2017-02-11
      • 2016-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多