次の XML をスキーマに対して検証すると、名前空間のプレフィックスが付いていない限り、KeyB の参照属性は欠落/未宣言としてマークされます。「インライン」と宣言されている KeyA の同様の属性は、正常に検証されます。誰かが私にこれを説明できますか?(注: 検証には .NET の XmlReader を使用します)。
スキーマ:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="so"
targetNamespace="http://test/so.xsd"
elementFormDefault="qualified"
xmlns="http://test/so.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="Id" type="xs:unsignedByte" />
<xs:attribute name="Index" type="xs:unsignedByte" />
<xs:element name="KeyA">
<xs:complexType>
<xs:attribute name="Id" type="xs:unsignedByte" use="required" />
<xs:attribute name="Index" type="xs:unsignedByte" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="KeyB">
<xs:complexType>
<xs:attribute ref="Id" use="required" />
<xs:attribute ref="Index" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="Keys">
<xs:complexType>
<xs:all>
<xs:element ref="KeyA"/>
<xs:element ref="KeyB"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
XML インスタンスの例:
<?xml version="1.0" encoding="utf-8" ?>
<Keys xmlns="http://test/so.xsd">
<KeyA Id="0" Index="3"/>
<KeyB Id="0" Index="3"/>
</Keys>
KeyB 要素について次のエラー メッセージが表示されます。
The required attribute 'http://test/so.xsd:Index' is missing.
The required attribute 'http://test/so.xsd:Id' is missing.
The 'Index' attribute is not declared.
The 'Id' attribute is not declared.