共用方式為


SimpleContent 項目繫結支援

.NET Framework 會提供 <simpleContent> 項目的部分繫結支援。

在 .NET Framework 中,永遠都會透過類別定義來完整表示簡單內容,但不會辨識簡單內容限制。

說明

XML 結構描述定義語言會使用 <simpleContent> 項目,定義不包含子項目的複雜型別。內含簡單內容 (屬性或本文或者兩者都是) 的複雜型別是透過擴充或限制,使用 <simpleContent> 項目底下的 <extension><restriction> 項目從基底型別 (Base Type) 衍生而來。

Xsd.exe 不會辨識簡單內容限制。在 .NET Framework 中,永遠都會透過類別定義來完整表示簡單內容,從 XML 結構描述文件產生原始程式碼時,Xsd.exe 會產生對應到基底型別的型別公用欄位,而基底型別是由 <extension> 項目的 base 屬性指定。如需 XML 結構描述之內建簡單型別與 .NET Framework 型別之間繫結的資訊,請參閱 .NET Framework Developer's Guide 中的<XML 結構描述 (XSD) 型別和 .NET Framework 型別間支援的資料型別>。

在結構描述物件模型中表示簡單內容擴充和限制的方式,是分別透過類別 XmlSchemaSimpleContentExtensionXmlSchemaSimpleContentRestriction,以及透過 XmlSchemaSimpleContent 類別。

這些類別的物件可以用來以程式設計的方式建立結構描述物件模型,此模型所對應的 XSD 物件會定義內含簡單內容的複雜型別。

範例

輸入 XML 結構描述文件:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            targetNamespace="http://example.org/" xmlns="http://example.org/" elementFormDefault="qualified">
<xsd:element name="Distance">
  <xsd:complexType>
   <xsd:simpleContent>
    <xsd:extension base="xsd:float">
     <xsd:attribute name="units" type="xsd:string"/>
    </xsd:extension>
   </xsd:simpleContent>
  </xsd:complexType>
 </xsd:element>
</xsd:schema>

由前面的 XML 結構描述文件所產生的 C# 類別:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://example.org/", IsNullable=false)]
public class Distance {
        
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string units;
        
    [System.Xml.Serialization.XmlTextAttribute()]
    public System.Single Value;
}

XML 結構描述項目和複雜型別會從前面 C# 原始檔所編譯的組件而產生:

<xs:element name="Distance" type="tns:Distance" />
<xs:complexType name="Distance">
  <xs:simpleContent>
    <xs:extension base="xs:float">
      <xs:attribute name="units" type="xs:string" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>
可能的屬性 繫結支援

id

Xsd.exe 公用程式忽略試圖提供唯一識別項的 id 屬性。

可能的父項目:<complexType>

可能的子項目:<annotation><extension><restriction>

請參閱

參考

XmlSchemaSimpleContent

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.