gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:00:07 25 4
gpt4 key购买 nike

对于这个解释,我使用了 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com