具有序列和屬性的全域性 ComplexType

此示例顯示了 complexType 的簡單全域性定義。該定義被認為是全域性的,因為它是 xs:schema 的子代。全域性定義的型別可以在架構中的其他位置使用。

這是宣告全域性 xs:complexType 的最常見形式,它使用 xs:sequence,xs:choice 或 xs:all 定義子元素,並且還可以選擇具有屬性。

注意:因為它是全域性定義的,所以它必須在模式集中具有唯一的名稱。

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2017 (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="PersonType">
        <xs:sequence>
            <xs:element name="Forename" type="xs:string" />
            <xs:element name="Surname" type="xs:string" />
        </xs:sequence>
        <xs:attribute name="Gender">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="male" />
                    <xs:enumeration value="female" />
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>
</xs:schema>

StackOverflow 文件