0

XSD<xs:key><xs:keyref>要素を使用して、カスタム XML 形式でキーと参照の制約を適用しようとしています。私が望むように機能していません。

最初に、私の XML 形式の例を示します。

<room xmlns="http://example.com">
  <box>
    <item name="x" uses="y" />
    <item name="y" uses="z" />
    <item name="z" />
    <box>
      <item name="p" uses="q" />
      <item name="q" uses="r" />
      <item name="r" />
      <box>
      </box>
    </box>
  </box>
</room>

このデータ構造は、単一の「ボックス」を含む「部屋」を表します。ボックスには、アイテムと他のボックスを含めることができます。ボックスは空にすることもできます。ボックス内のアイテムには個別の名前を付ける必要があり (ただし、他のボックス内のアイテムと名前を共有できます)、同じボックス内の他のアイテムのみを「使用」できます。

適切な属性でキー/キー参照を使用して、「uses」グラフの整合性を維持しようとしています。ただし、以下のスキーマを使用してこの XML で Xerces 2 バリデーターを使用すると、次のエラーが発生します。

[Error] file:///example.xml:13:11: cvc-identity-constraint.4.3: Key 'ItemKeyRef' with value 'q' not found for identity constraint of element 'box'.
[Error] file:///example.xml:14:9: cvc-identity-constraint.4.3: Key 'ItemKeyRef' with value 'y' not found for identity constraint of element 'box'.

スキーマ:

<xs:schema
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:example="http://example.com"
  targetNamespace="http://example.com"
  elementFormDefault="qualified"
  attributeFormDefault="unqualified">

  <xs:element name="room" type="example:Room" />

  <xs:complexType name="Room">
    <xs:all>
      <xs:element ref="example:box" />
    </xs:all>
  </xs:complexType>

  <xs:element name="box" type="example:Box">
    <xs:keyref name="ItemKeyRef" refer="example:ItemKey">
      <xs:selector xpath="./example:item" />
      <xs:field xpath="@uses" />
    </xs:keyref>
    <xs:key name="ItemKey">
      <xs:selector xpath="./example:item" />
      <xs:field xpath="@name" />
    </xs:key>
  </xs:element>

  <xs:complexType name="Box">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="item" type="example:Item" />
      <xs:element ref="example:box" />
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="Item">
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="uses" type="xs:string" />
  </xs:complexType>
</xs:schema>

私は何か非常に間違ったことをしているように感じます。このエラーが発生するのはなぜですか? これは検証すべきではありませんか?

4

1 に答える 1

1

私が使用した Xerces2 Java Parser 2.11.0 には、再帰的な要素定義とキー/キー参照を使用する際にいくつかのバグが含まれていることがわかりました。oXygen XML Developer を使用して上記の XML を検証しようとしたところ、成功したため、 Apache の問題トラッカーのバグ レポートが正確であると確信しました。

于 2015-01-23T10:10:45.953 に答える