xml - XSD 错误 : Type is not declared, 或不是简单类型

标签 xml xsd xsd-validation xml-validation

对于这个解释,我使用了 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 社区抛出错误:

Type 'http://tempuri.org/element_ArtStyleSuffix.xsd:customEntry' is not declared, or is not a simple type.



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

最佳答案

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

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

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

以便您可以在 xs:union 中使用它宣言:
<xs:union memberTypes="ce:customEntry enum_ArtStyleSuffix"/>

你的错误就会消失。

旁注 :这是可以接受的,但既不需要也不习惯将命名空间命名为 XSD 文件的 URL;考虑放弃 .xsd延期。

关于xml - XSD 错误 : Type is not declared, 或不是简单类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36634533/

相关文章:

xml - 对分组的父元素 XSLT 中的子元素进行分组

python - lxml 包含相对路径

xml - XSD 中 <all> <sequence> <choice> 和 <group> 的区别?

xml - 根据其他 XML 字段的值在 XSD 中设置 minOccurs 和 maxOccurs?

java - 在 Java 1.8 中针对 XSD v1.1 架构验证 xml 文件的示例

xml - XSLT 从 XML 输出 html 标签

json - 如何同时使用 xml/json 和 form-urlencoded?

java - 设置首选项(在 PreferenceFragment 内)响应单击

java - 如何告诉 JAXB 添加 noNameSpaceSchemaLocation 属性

java - PMML文档解析