XSD Text-Only Elements
一個複雜的純文字元素可以包含文字和屬性。
複雜純文字元素
此型別僅包含簡單內容(文字和屬性),因此我們在內容周圍添加了 simpleContent 元素。使用 simpleContent 時,您必須在 simpleContent 元素內定義一個 extension 或 restriction,如下所示:
<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="basetype">
....
....
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
OR(或)
<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="basetype">
....
....
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>
提示:使用 extension/restriction 元素來擴充套件或限制元素的基元型別。
以下是一個 XML 元素 "shoesize" 的示例,它只包含文字:
<shoesize country="france">35</shoesize>
下面的示例聲明瞭一個名為 "shoesize" 的 complexType。內容定義為整數值,並且 "shoesize" 元素還包含一個名為 "country" 的屬性。
<xs:element name="shoesize">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
我們也可以給 complexType 元素命名,並讓 "shoesize" 元素有一個 type 屬性,指向 complexType 的名稱(如果使用此方法,可以有多個元素引用同一個 complex type)。
<xs:element name="shoesize" type="shoetype"/>
<xs:complexType name="shoetype">
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>