can i use a qualifed attribute in a xs:field element
Posted: Tue Mar 29, 2022 12:13 am
I want to have an XSD schema that has an identity-constraint to ensure values in "code" attributes can be used as a key identity. the code attribute belong to a namesapce (code attribute must be qualified).
When i try to validate the following document XML against the above xsd file, I get this error:
cvc-identity-constraint.4.2.1.a: Element "list" has no value for the key "personKey".
Code: Select all
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="test.org"
elementFormDefault="qualified" attributeFormDefault= 'qualified'
xmlns:p = 'test.org'>
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:element name="person" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="first" type="xs:string"/>
<xs:element name="last" type="xs:string"/>
</xs:sequence>
<xs:attribute name="code" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="personKey">
<xs:selector xpath="p:person"/>
<xs:field xpath="@code"/>
</xs:key>
</xs:element>
</xs:schema>
cvc-identity-constraint.4.2.1.a: Element "list" has no value for the key "personKey".
Code: Select all
<list xmlns="test.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="test.org test.xsd">
<person xmlns:p="test.org" p:code="code1">
<first>first0</first>
<last>last0</last>
</person>
<person xmlns:p="test.org" p:code="code2">
<first>first1</first>
<last>last1</last>
</person>
</list>