XMLオブジェクト
より微調整された XML モデル定義を可能にするメタデータ オブジェクト。
配列を使用する場合、XML 要素名は(単数形/複数形の場合) 推論されないため、その情報を追加するためにnameプロパティを使用する必要があります (SHOULD)。予想される動作については例を参照してください。
固定フィールド
| フィールド名 | タイプ | 説明 |
|---|---|---|
| 名前 | string | 記述されたスキーマ プロパティに使用される要素/属性の名前を置き換えます。items内で定義すると、リスト内の個々の XML 要素の名前に影響します。typeがarrayと一緒に( itemsの外側で)定義されている場合は、wrappedが trueの場合にのみ、ラッピング要素に影響します。falseの場合は無視されます。 |
| 名前空間 | string | 名前空間定義の URI。これは絶対 URI の形式でなければなりません。 |
| 接頭辞 | string | 名前に使用されるプレフィックス。 |
| 属性 | boolean | プロパティ定義を要素ではなく属性に変換するかどうかを宣言します。デフォルト値は falseです。 |
| 包まれた | boolean | 配列定義にのみ使用できます (MAY)。配列がラップされている (たとえば、<books><book/><book/></books>) かラップされていない ( <book/><book/>) かを示します。デフォルト値は falseです。この定義は、type存在とarray並行して( itemsの外側で) 定義された場合にのみ有効になります。 |
このオブジェクトは、仕様拡張機能を使用して拡張できます。
XML オブジェクトの例
XML オブジェクト定義の例は、スキーマ オブジェクトのプロパティ定義内に、その XML 表現のサンプルとともに含まれています。
XML要素がありません
基本的な文字列プロパティ:
{ "animals": { "type": "string" }}
animals: type: string
<animals>...</animals>
基本的な文字列配列プロパティ (デフォルトでwrappedはfalseです。):
{ "animals": { "type": "array", "items": { "type": "string" } }}
animals: type: array items: type: string
<animals>...</animals><animals>...</animals><animals>...</animals>
XML 名の置換
{ "animals": { "type": "string", "xml": { "name": "animal" } }}
animals: type: string xml: name: animal
<animal>...</animal>
XML 属性、プレフィックス、名前空間
この例では、完全なモデル定義が示されています。
{ "Person": { "type": "object", "properties": { "id": { "type": "integer", "format": "int32", "xml": { "attribute": true } }, "name": { "type": "string", "xml": { "namespace": "https://example.com/schema/sample", "prefix": "sample" } } } }}
Person: type: object properties: id: type: integer format: int32 xml: attribute: true name: type: string xml: namespace: https://example.com/schema/sample prefix: sample
<Person id="123"> <sample:name xmlns:sample="https://example.com/schema/sample">example</sample:name></Person>
XML配列
要素名の変更:
{ "animals": { "type": "array", "items": { "type": "string", "xml": { "name": "animal" } } }}
animals: type: array items: type: string xml: name: animal
<animal>value</animal><animal>value</animal>
外部nameプロパティは XML には影響しません。
{ "animals": { "type": "array", "items": { "type": "string", "xml": { "name": "animal" } }, "xml": { "name": "aliens" } }}
animals: type: array items: type: string xml: name: animal xml: name: aliens
<animal>value</animal><animal>value</animal>
配列がラップされている場合でも、名前が明示的に定義されていない場合は、内部と外部の両方で同じ名前が使用されます。
{ "animals": { "type": "array", "items": { "type": "string" }, "xml": { "wrapped": true } }}
animals: type: array items: type: string xml: wrapped: true
<animals> <animals>value</animals> <animals>value</animals></animals>
上記の例の名前付けの問題を解決するには、次の定義を使用できます。
{ "animals": { "type": "array", "items": { "type": "string", "xml": { "name": "animal" } }, "xml": { "wrapped": true } }}
animals: type: array items: type: string xml: name: animal xml: wrapped: true
<animals> <animal>value</animal> <animal>value</animal></animals>
内部名と外部名の両方に影響します。
{ "animals": { "type": "array", "items": { "type": "string", "xml": { "name": "animal" } }, "xml": { "name": "aliens", "wrapped": true } }}
animals: type: array items: type: string xml: name: animal xml: name: aliens wrapped: true
<aliens> <animal>value</animal> <animal>value</animal></aliens>
外部要素は変更するが、内部要素は変更しない場合:
{ "animals": { "type": "array", "items": { "type": "string" }, "xml": { "name": "aliens", "wrapped": true } }}
animals: type: array items: type: string xml: name: aliens wrapped: true
<aliens> <aliens>value</aliens> <aliens>value</aliens></aliens>