Xsd-complex-types
提供:Dev Guides
XSD-複合型
複合要素は、他の要素や属性を含むことができるXML要素です。 私たちは2つの方法で複雑な要素を作成できます-
- 複合型を定義し、 type 属性を使用して要素を作成します
- 名前を付けて直接複合型を定義する
複合型を定義してから、type属性を使用して要素を作成します。
<xs:complexType name = "StudentType">
<xs:sequence>
<xs:element name = "firstname" type = "xs:string"/>
<xs:element name = "lastname" type = "xs:string"/>
<xs:element name = "nickname" type = "xs:string"/>
<xs:element name = "marks" type = "xs:positiveInteger"/>
</xs:sequence>
<xs:attribute name = 'rollno' type = 'xs:positiveInteger'/>
</xs:complexType>
<xs:element name = 'student' type = 'StudentType'/>
名前を付けることにより、複合型を直接定義します。
<xs:element name = "student">
<xs:complexType>
<xs:sequence>
<xs:element name = "firstname" type = "xs:string"/>
<xs:element name = "lastname" type = "xs:string"/>
<xs:element name = "nickname" type = "xs:string"/>
<xs:element name = "marks" type = "xs:positiveInteger"/>
</xs:sequence>
<xs:attribute name = 'rollno' type = 'xs:positiveInteger'/>
</xs:complexType>
<xs:element>
以下は、XSDがサポートする複合型のリストです。
S.No. | Simple Type & Description |
---|---|
1 |
複合空の複合型要素は属性のみを持つことができ、内容は持つことができません。 |
2 |
要素のみの複合型要素には要素のみを含めることができます |
3 |
テキストのみの複合型要素には、属性とテキストのみを含めることができます。 |
4 |
混合複合型要素には、要素、属性、およびテキストを含めることができます。 |
5 |
インジケータは、XMLドキュメントで要素を整理する方法を制御します。 |
6 |
<any>要素は、スキーマで定義されていない要素に使用されます |
7 |
<anyAttribute>属性は、スキーマで定義されていない属性に使用されます。 |