XMLチュートリアル

XMLホーム XMLの紹介 XML使用方法 XMLツリー XML構文 XML要素 XML属性 XML名前空間 XML表示 XML HttpRequest XMLパーサー XML DOM XML XPath XML XSLT XML XQuery XML XLink XMLバリデーター XML DTD XMLスキーマ XMLサーバー XMLの例 XMLクイズ XML証明書

XML AJAX

AJAXの紹介 AJAX XMLHttp AJAXリクエスト AJAX応答 AJAXXMLファイル AJAX PHP AJAX ASP AJAXデータベース AJAXアプリケーション AJAXの例

XML DOM

DOMの紹介 DOMノード DOMアクセス DOMノード情報 DOMノードリスト DOMトラバース DOMナビゲーション DOMは値を取得します DOM変更ノード DOM削除ノード DOM置換ノード DOM作成ノード DOM追加ノード DOMクローンノード DOMの例

XPathチュートリアル

XPathの概要 XPathノード XPath構文 XPath軸 XPath演算子 XPathの例

XSLTチュートリアル

XSLTの紹介 XSL言語 XSLT変換 XSLT <テンプレート> XSLT <値> XSLT <for-each> XSLT <ソート> XSLT <if> XSLT <選択> XSLT適用 クライアント上のXSLT サーバー上のXSLT XSLT Edit XML XSLTの例

XQueryチュートリアル

XQueryの紹介 XQueryの例 XQuery FLWOR XQuery HTML XQueryの用語 XQuery構文 XQuery追加 XQuery Select XQuery関数

XML DTD

DTDの紹介 DTDビルディングブロック DTD要素 DTD属性 DTD要素と属性 DTDエンティティ DTDの例

XSDスキーマ

XSDの概要 XSDハウツー XSD <スキーマ> XSD要素 XSD属性 XSDの制限

XSDコンプレックス

XSD要素 XSDが空です XSD要素のみ XSDテキストのみ XSD混合 XSDインジケーター XSD <任意> XSD <anyAttribute> XSD置換 XSDの例

XSDデータ

XSD文字列 XSD日付 XSD数値 XSDその他 XSDリファレンス

Webサービス

XMLサービス XML WSDL XML SOAP XML RDF XML RSS

参考文献

DOMノードタイプ DOMノード DOM NodeList DOM NamedNodeMap DOMドキュメント DOM要素 DOM属性 DOMテキスト DOM CDATA DOMコメント DOM XMLHttpRequest DOMパーサー XSLT要素 XSLT / XPath関数

XMLスキーマ属性要素


❮完全なXMLスキーマリファレンス

定義と使用法

属性要素は属性を定義します。

要素情報

  • 親要素: attributeGroup、schema、complexType、restriction(simpleContentとcomplexContentの両方)、extension(simpleContentとcomplexContentの両方)

構文

<attribute
default=string
fixed=string
form=qualified|unqualified
id=ID
name=NCName
ref=QName
type=QName
use=optional|prohibited|required
any attributes
>

(annotation?,(simpleType?))

</attribute>

(?記号は、要素が属性要素内で0回または1回発生する可能性があることを宣言します)

Attribute Description
default Optional. Specifies a default value for the attribute. Default and fixed attributes cannot both be present
fixed Optional. Specifies a fixed value for the attribute. Default and fixed attributes cannot both be present
form Optional. Specifies the form for the attribute. The default value is the value of the attributeFormDefault attribute of the element containing the attribute. Can be set to one of the following:
  • "qualified" - indicates that this attribute must be qualified with the namespace prefix and the no-colon-name (NCName) of the attribute
  • unqualified - indicates that this attribute is not required to be qualified with the namespace prefix and is matched against the (NCName) of the attribute
id Optional. Specifies a unique ID for the element
name Optional. Specifies the name of the attribute. Name and ref attributes cannot both be present
ref Optional. Specifies a reference to a named attribute. Name and ref attributes cannot both be present. If ref is present, simpleType element, form, and type cannot be present
type Optional. Specifies a built-in data type or a simple type. The type attribute can only be present when the content does not contain a simpleType element
use Optional. Specifies how the attribute is used. Can be one of the following values:
  • optional - the attribute is optional (this is default)
  • prohibited - the attribute cannot be used
  • required - the attribute is required
any attributes Optional. Specifies any other attributes with non-schema namespace

例1

<xs:attribute name="code">

<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:pattern value="[A-Z][A-Z]"/>
  </xs:restriction>
</xs:simpleType>

</xs:attribute>

上記の例は、「code」属性に制限があることを示しています。唯一の許容値は、aからzまでの2つの大文字です。

例2

複合型内の既存の属性定義を使用して属性を宣言するには、ref属性を使用します。

<xs:attribute name="code">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z][A-Z]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:attribute>

<xs:complexType name="someComplexType">
  <xs:attribute ref="code"/>
</xs:complexType>

例3

属性には、デフォルト値または固定値のいずれかを指定できます。他の値が指定されていない場合、デフォルト値が属性に自動的に割り当てられます。次の例では、デフォルト値は「EN」です。

<xs:attribute name="lang" type="xs:string" default="EN"/>

他の値が指定されていない場合も、固定値が属性に自動的に割り当てられます。ただし、デフォルト値とは異なります。固定値以外の値を指定すると、ドキュメントは無効と見なされます。次の例では、固定値は「EN」です。

<xs:attribute name="lang" type="xs:string" fixed="EN"/>

例4

デフォルトでは、すべての属性はオプションです。属性がオプションであることを明示的に指定するには、「use」属性を使用します。

<xs:attribute name="lang" type="xs:string" use="optional"/>

属性を必須にするには:

<xs:attribute name="lang" type="xs:string" use="required"/>

❮完全なXMLスキーマリファレンス