XSD Error: Type is not declared, or is not a simple type

狂风中的少年 提交于 2021-02-19 04:46:26

问题


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>

My problem is with the following line:

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

Visual Studio 2015 community is throwing the error:

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

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?


回答1:


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...

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

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

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

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

and your error will go away.

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



来源:https://stackoverflow.com/questions/36634533/xsd-error-type-is-not-declared-or-is-not-a-simple-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!