Xsd-attribute
提供:Dev Guides
XSD-属性
属性は、XML要素の属性を表します。 XSDはそれを単純型として定義します。
構文
<xs:attribute name = "attribute-name" type = "attribute-type"/>
attribute-name |
Name of the Attribute. For example,
XML要素で使用できる次のrollno属性を定義します。 例えば
|
attribute-type |
Type of the Attribute. For example,
属性の型を整数として定義します。rollnoはint型の値を持つ必要があります。
|
例
次のXML要素を検討してください
<student rollno = "393"/>
*rollno* 属性のXSD宣言は次のようになります-
<xs:attribute name = "rollno" type = "xs:integer"/>
デフォルト値
属性には、デフォルト値を割り当てることができます。 属性に値がない場合、デフォルト値が使用されます。
<xs:attribute name = "grade" type = "xs:string" default = "NA"/>
固定値
属性に修正値を割り当てることができます。 固定値が割り当てられている場合、要素には値を設定できません。
<xs:attribute name = "class" type = "xs:string" fixed = "1"/>
制限
属性はデフォルトでオプションです。 ただし、属性を必須にするには、「use」属性を使用できます。
<xs:attribute name = "rollno" type = "xs:integer" use = "required"/>