目標:是否可以在XSD中使用xs:重新定義xs:complexType元素以要求type屬性?
創建在需要爲每一個XS「類型」屬性的XSD:在架構中定義元素
能夠重新使用重新定義
http://www.w3.org/2001/XMLSchema
其他架構強制所有定義的xs:元素(一個或多個)要求的「類型」屬性
例如,我想下面的是在我們的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(無Service Pack)的一些奇怪的行爲:
在 「文本」 的說法,並試圖保存,XMLSpy的顯示模式爲「無效」
在「綱要」的說法,並試圖保存,XMLSpy的顯示模式是有效的
嘗試到c在XMLSpy中創建示例XML文件將導致錯誤,指示該模式無效
模式中不應有效的唯一部分是
<xs:element name="SomeElement">
,因爲它尚未用「type」屬性定義。發生的錯誤與重複聲明有關;但正在嘗試的是重新定義而不是另一個聲明。
問題:
- 是否有可能重新定義
<xs:complexType name="element">
要求 「類型」 屬性? - 是否有可能在其他XSD中使用此重新定義的類型與不同的「targetNamespace」?