List 要素のバインディング サポート

このトピックの対象は、レガシ テクノロジに特定されています。XML Web サービスと XML Web サービス クライアントは以下を使用して作成してください。 Windows Communication Foundation.

.NET Framework では、<list> 要素のバインディングを一部サポートしています。

.NET Framework では、リスト型を持つ XML 属性宣言に対して正確なバインディングが提供されていますが、要素宣言に対しては提供されていません。

説明

<list> 構造体は、空白文字で区切られた他の単純型からの一連の値が使用可能な値である単純型を定義するために使用されます。ビルド ブロックとして機能する型は、意味のある単位に分割できないため、原子型と呼ばれます。すべての単純型は、リスト型または共用体を除き、原子型です。

値が空白で区切られた 10 進数であるリスト型を作成する例を次に示します。

<xsd:simpleType name="numbersList">
  <xsd:list itemType="xsd:Decimal"/>
</xsd:simpleType>

.NET Framework では、属性型を定義する場合 <list> 要素に対してバインディングが提供されていますが、要素型に対しては提供されていません。

XML スキーマ ドキュメントからソース コードを生成しているとき、リスト型を持つ要素が存在する場合、Xsd.exe は itemTypeXmlAttributeAttribute 属性の値であり、リストの構成要素型に対応する .NET Framework 型を持つフィールドを作成します。文字列ベースの型の場合、文字列の文字列は文字列であるため、この変換は理論的に正しいものです。上記の例の 10 進ベース型など、その他の単純型に基づくリスト型の場合、変換はエラーとなります。

リスト型を持つ属性が存在する場合、Xsd.exe は itemType 属性の値に対応する .NET Framework 型の配列である型を持つフィールドを作成します。フィールドは、属性と共に表示されます。生成されるフィールドの例を次に示します。

[System.Xml.Serialization.XmlAttributeAttribute()]
public System.Decimal[] numbers;

同様に、一組のクラスから XML スキーマ ドキュメントを生成しているとき、Xsd.exe はリスト型を生成するフィールドやプロパティで次の条件を検索します。

  • フィールドやプロパティの型は、単純型にマップできる型の配列です。

  • フィールドまたはプロパティは XmlAttribute 属性と共に表示されます。

この組み合わせは <list> 型としてのみ表現できます。これは、XML 属性には単純型が必要であり、それ以外の場合、配列が unbounded に設定された maxOccurs 属性を持つ複合型にバインドされるためです。

入力 XML スキーマ ドキュメント :

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            targetNamespace="http://example.org/" xmlns="http://example.org/" elementFormDefault="qualified">
    <xsd:element name="alphabet" type="AlphabetType"/>

    <xsd:complexType name="AlphabetType">
        <xsd:sequence>
            <xsd:element name="language" type="xsd:string"/>
            <xsd:element name="count" type="xsd:decimal"/>
        </xsd:sequence>
        <xsd:attribute name="letters">
            <xsd:simpleType>
                <xsd:list itemType="Character"/>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>

    <xsd:simpleType name="Character">
        <xsd:restriction base="xsd:string">
            <xsd:length value="1"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>

上記の XML スキーマ ドキュメントから生成される C# クラス :

[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
[System.Xml.Serialization.XmlRootAttribute("alphabet", Namespace="http://example.org/", IsNullable=false)]
public class AlphabetType {
        
    public string language;
        
    public System.Decimal count;
        
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string[] letters;
}

上記の C# ソースからコンパイルされたアセンブリから生成される XML スキーマ複合型:

<xs:complexType name="AlphabetType">
  <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="1" name="language" type="xs:string" />
    <xs:element minOccurs="1" maxOccurs="1" name="count" type="xs:decimal" />
  </xs:sequence>
  <xs:attribute name="letters">
    <xs:simpleType>
      <xs:list itemType="xs:string" />
    </xs:simpleType>
  </xs:attribute>
</xs:complexType>

使用可能な属性 バインディング サポート

id

Xsd.exe ユーティリティは、一意な識別子を提供するための id 属性を無視します。

itemType

リスト型が XML 属性として使用され、要素として使用されない場合、Xsd.exe ツールは itemType 属性の値に対応する .NET Framework 型の配列であるフィールドを作成します。

使用可能な親要素 : <simpleType>

使用可能な子要素 : <annotation><simpleType>

参照

リファレンス

XmlSchemaSimpleTypeList