包含对 complexType 元素(它以字符数据或 simpleType 元素为内容)的扩展或限制并且不包含任何元素。
<simpleContent
id = ID
{any attributes with non-schema Namespace}...>
Content: (annotation?, (restriction | extension))
</simpleContent>
属性
id
该元素的 ID。 id 值必须属于类型 ID 并且在包含该元素的文档中是唯一的。可选项。
元素信息
出现次数 |
一次 |
父元素 |
|
内容 |
可选项 — annotation 必选项 — 有并且只有一个下列元素: restriction (simpleContent) 或 extension (simpleContent)。 |
备注
simpleContent 元素使您可以将一个元素指定为包含其中没有任何元素的 simpleType,但会使您可以限制该元素的内容的值或通过属性扩展该元素。 例如,以下元素声明不允许添加属性(例如 sizing)。
<xs:element name="shoeSize" type="xs:decimal"/>
示例
使用 simpleContent 元素,以下元素声明包含 complexType 元素,该元素将元素内容定义为具有单个属性 (sizing) 的 decimal 类型。
<xs:element name="shoeSize">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="sizing">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="US"/>
<xs:enumeration value="European"/>
<xs:enumeration value="UK"/>
<xs:enumeration value="Japan"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
注释
必须通过下列方法之一定义简单内容。
restriction 元素 |
将元素值的范围限制为继承的 simpleType 的那些值的子集。 |
extension 元素 |
通过添加属性扩展元素的 simpleType 内容。 |
示例
以下示例说明使用匿名 complexType(没有名称的 complexType)声明的元素 (generalPrice),该元素将其内容定义为 decimal 数据类型并且具有 currency 属性。
<xs:element name="generalPrice">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="currency" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
其他资源
有关更多信息,请参见“W3C XML Schema Part 1: Structures Recommendation”(W3C XML 架构第 1 部分:结构建议),网址为 www.w3.org/TR/2001/REC-xmlschema-1-20010502/\#element-all。