Hi, I am trying to specify a KeyRef that may either refer to a value or be empty. I have found different results with attributes and simple content. I'm not sure what the intension of the spec is in this regard, so I don't know if this behavior is a bug in Xerces or in accordance with what the spec intended.
ATTRIBUTES Please refer to the attached test.xsd. A person has an attribute "manager-id" which refers to another person's "id" attribute. Use of this attribute is specified as optional. In test.xml the first person does not have this attribute. This behaves correctly and the parser does not give an error. SIMPLE CONTENT This same xsd specifies that the root element may contain "person" elements as well as "dog" elements. A person can have a child element called "dog-name" which refers to a "dog" element. Nillable has been set to true so that "dog-name" can be empty (nil). I specifically don't want to remove the "dog-name" element, but just create an empty "dog-name", as with the second person in test.xml. I get the following parser error, which means that it doesn't allow the nil value for "dog-name" even though dog-name has been set to nillable: Line 13: Parser error: Key 'person.dog-name' with value 'ID Value: ' not found for identity constraint of element 'personnel'. Please let me know if I am misinterpreting the spec or whether this is a bug. Thanks in advance, Evert
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'> <xs:element name="personnel"> <xs:complexType> <xs:sequence> <xs:element ref="person" minOccurs='1' maxOccurs='unbounded'/> <xs:element ref="dog" minOccurs='1' maxOccurs='unbounded'/> </xs:sequence> </xs:complexType> <xs:unique name="person.id"> <xs:selector xpath="person"/> <xs:field xpath="@id"/> </xs:unique> <xs:unique name="dog"> <xs:selector xpath="dog"/> <xs:field xpath="."/> </xs:unique> <xs:keyref name="person.dog-name" refer="dog"> <xs:selector xpath="person"/> <xs:field xpath="dog-name"/> </xs:keyref> <xs:keyref name="person.manager-id" refer="person.id"> <xs:selector xpath="person"/> <xs:field xpath="@manager-id"/> </xs:keyref> </xs:element> <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="dog-name" type="xs:string" nillable="true" minOccurs='0' maxOccurs='1'/> </xs:sequence> <xs:attribute name="id" type="xs:ID" use='required'/> <xs:attribute name="manager-id" type="xs:string" use="optional"/> </xs:complexType> </xs:element> <xs:element name="dog" type="xs:string"/> </xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd"> <person id="Big.Boss"> <name>Big Boss</name> <dog-name>fluffy</dog-name> </person> <person id="one.worker" manager-id="Big.Boss"> <name>One Worker</name> <dog-name/> </person> <dog>fluffy</dog> <dog>pit</dog> </personnel>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]