XSD 错误:类型未声明,或不是简单类型 [英] XSD Error: Type is not declared, or is not a simple type

查看:35
本文介绍了XSD 错误:类型未声明,或不是简单类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For this explanation I am using 2 different XSDs:

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 社区抛出错误:

Visual Studio 2015 community is throwing the error:

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

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

It looks like a simple type to me and I thought the import line declared it, so maybe I don't understand "import" fully cause I'm not receiving any errors from the import line just the union line. Am I doing this correctly?

推荐答案

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

It is indeed a simply type. However, it is not declared in the target namespace of the current XSD; it's declared in the namespace of the imported XSD. Reference customEntry in the imported http://tempuri.org/customEntry.xsd namespace to eliminate the error...

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

Specifically, declare a namespace prefix on the xs:schema element of your main XSD:

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

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

so that you can use it in your xs:union declaration:

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

你的错误就会消失.

附注:这是可以接受的,但既不要求也不习惯将命名空间命名为 XSD 文件的 URL;考虑删除 .xsd 扩展名.

Side note: It's acceptable, but neither required nor conventional to name your namespaces as URLs to XSD files; consider dropping the .xsd extension.

这篇关于XSD 错误:类型未声明,或不是简单类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆