共用方式為


<xsd:simpleContent> 項目

在具有字元資料的 complexType 項目或做為內容且未包含項目的 simpleType 項目上包含擴充部分或限制。

<simpleContent
  id = ID 
  {any attributes with non-schema Namespace}...>
Content: (annotation?, (restriction | extension))
</simpleContent>

屬性

  • id
    這個項目的 ID。id 值必須是型別 ID,且在包含此項目的文件中是唯一的。

    選擇性項目。

項目資訊

發生次數

一次

父項目

complexType

內容

選擇性 — 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 (沒有名稱) 宣告的項目 (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 結構描述第一部:結構建議事項>(英文),網址為:www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-all。

另請參閱

參考

XML 結構描述 (XSD) 參考
XML 結構描述項目