通過限制現有的 xscomplexType 來建立全域性 xscomplexType

這是事情變得有點棘手的地方。我們現在限制現有的 xs:complexType。我們的 SolidStateDriveType 派生自 HardDiskType,但刪除了 spinUpTime 屬性和 RotationSpeed 元素。

請注意,處理屬性和元素的方法是不同的。要刪除屬性,你需要重新宣告它並將其用途設定為禁止。對於只是不重新宣告它們的元素將導致它們被排除,實際上你需要重新宣告你想要保留在新型別中的任何元素。

受限型別的關鍵概念 :必須可以將受限型別的 XML 例項元素載入到基型別中,另一種方式是受限型別需要能夠適應*基型別。因此,你不能排除強制屬性或元素,為了在限制型別中排除它,它必須在基型別中是可選的。如果更改受限型別中元素或屬性的型別/構面規則,則新型別/構面規則必須與基型別相容,因此如果基型別為短,則受限型別可以是位元組,但是不久。*

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2017 - Developer Bundle Edition (Trial) 15.0.2.7192 (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="HardDiskType">
        <xs:sequence>
            <xs:element name="Capacity" type="xs:long" />
            <xs:element name="RotationSpeed" type="xs:int" minOccurs="0" />
        </xs:sequence>
        <xs:attribute name="name" type="xs:string" />
        <xs:attribute name="spinUpTime" type="xs:time" />
    </xs:complexType>
    <xs:complexType name="SolidStateDrive">
        <xs:complexContent>
            <xs:restriction base="HardDiskType">
                <xs:sequence>
                    <xs:element name="Capacity" type="xs:long" />
                </xs:sequence>
                <xs:attribute name="spinUpTime" use="prohibited" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>

StackOverflow 文件