【发布时间】:2013-07-11 09:22:46
【问题描述】:
目标:
创建一个 XSD,其中架构中定义的每个 xs:element 都需要“type”属性
能够在其他模式中重新使用重新定义的
http://www.w3.org/2001/XMLSchema,以强制所有已定义的 xs:element(s) 需要“type”属性
例如,我希望以下内容在我们的 XSD 中“无效”(例如在 XMLSpy 中)
<xs:element name="SomeElement"/>
而以下是有效的
<xs:element name="SomeElement" type="abc:SomeType"/>
这是我尝试重新定义<xs:complexType name="element"> 以要求“type”属性的架构示例。
<?xml version="1.0"?>
<!-- edited with XMLSpy v2013 (http://www.altova.com) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:redefine schemaLocation="http://www.w3.org/2001/XMLSchema.xsd">
<xs:complexType name="element" abstract="true">
<xs:complexContent>
<xs:restriction base="xs:element">
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:QName"/>
</xs:simpleType>
</xs:attribute>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="topLevelElement">
<xs:complexContent>
<xs:restriction base="xs:topLevelElement"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="localElement">
<xs:complexContent>
<xs:restriction base="xs:localElement"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="narrowMaxMin">
<xs:complexContent>
<xs:restriction base="xs:narrowMaxMin"/>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
<xs:element name="SomeElement"/>
</xs:schema>
现在,此架构有一些有趣的方面,以及 XMLSpy 2013(无服务包)中的一些奇怪行为:
在“文本”视图中,尝试保存时,XMLSpy 指示架构“无效”
在“架构”视图中,尝试保存时,XMLSpy 指示架构有效
尝试在 XMLSpy 中创建示例 XML 文件将导致错误提示架构无效
架构中唯一无效的部分是
<xs:element name="SomeElement">,因为它没有使用“类型”属性定义。出现的错误与重复声明有关;但正在尝试的是重新定义而不是另一个声明。
问题:
- 是否可以重新定义
<xs:complexType name="element">以要求“类型”属性? - 是否可以在具有不同“targetNamespace”的其他 XSD 中使用这种重新定义的类型?
【问题讨论】:
标签: xsd schema complextype xmlspy redefine