.NET Framework では、<simpleContent> 要素のバインディングを一部サポートしています。
単純コンテンツの拡張は、.NET Framework のクラス定義によって、常に完全に表現されます。単純コンテンツの制限は認識されません。
説明
XML スキーマ定義言語では、子要素を持たない複合型を定義するために、<simpleContent> 要素を使用します。単純コンテンツ (属性と本文テキストのどちらか、または両方) を含む複合型は、<simpleContent> 要素下の <extension> 要素または <restriction> 要素を使用する拡張または制限によって、基本型から派生します。
Xsd.exe では、単純コンテンツの制限が認識されません。単純コンテンツの拡張は、.NET Framework のクラス定義によって、常に完全に表現されます。XML スキーマ ドキュメントからソース コードを生成すると、Xsd.exe は、基本型に対応する型のパブリック フィールドを生成します。この基本型は、<extension> 要素の base 属性で指定されます。XML スキーマの組み込み単純型と .NET Framework 型の間のバインディングについては、『.NET Framework Developer's Guide』の「XML スキーマ (XSD) 型と .NET Framework 型の間でのデータ型のサポート」を参照してください。
単純コンテンツの拡張および制限は、それぞれ XmlSchemaSimpleContentExtension クラスおよび XmlSchemaSimpleContentRestriction クラス、そして両方に共通する 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;
}
上記の C# ソースからコンパイルされたアセンブリから生成される XML スキーマ要素および複合型 :
<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>****
関連項目
参照
Copyright © 2007 by Microsoft Corporation.All rights reserved.