- From: Mukul Gandhi <gandhi.mukul@gmail.com>
- Date: Mon, 14 Jan 2013 21:45:16 +0530
- To: George Cristian Bina <george@oxygenxml.com>
- Cc: xmlschema-dev@w3.org
- Message-ID: <CABuuzNN=NGYhtJ3OZgTeg=TG5WoW6+Cv8xvsZja7GToYF20A7w@mail.gmail.com>
Hi George,
As a workaround, with XSD 1.1 we can write an assertion on the
complexType of element "parent" as follows:
<xs:assert test="every $tst in test satisfies $tst/@ref =
child/element/@id"/>
This kind of simulates the keyref you've written.
On Mon, Jan 14, 2013 at 6:46 PM, George Cristian Bina
<george@oxygenxml.com>wrote:
> Hi all,
>
> I have problems identifying the relevant parts of the XML Schema spec that
> apply to the following example. There is a key defined on the "child"
> element selecting the "element/@id" attribute and a key reference defined
> on the "parent" element that specifies that "test/@ref" points to
> "child/element/@id" attributes:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <parent xmlns:xsi="http://www.w3.org/**2001/XMLSchema-instance<http://www.w3.org/2001/XMLSchema-instance>
> "
> xsi:noNamespaceSchemaLocation=**"test.xsd">
> <child>
> <element id="a1"/>
> <element id="a2"/>
> </child>
> <child>
> <element id="a1"/>
> <element id="a4"/>
> </child>
> <test ref="a2"/>
> <test ref="a1"/>
> </parent>
>
> test.xsd:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/**2001/XMLSchema<http://www.w3.org/2001/XMLSchema>"
> elementFormDefault="qualified"**>
> <xs:element name="parent">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="child" maxOccurs="unbounded">
> <xs:complexType>
> <xs:sequence maxOccurs="unbounded">
> <xs:element name="element">
> <xs:complexType>
> <xs:attribute name="id" use="required"/>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> <xs:key name="k">
> <xs:selector xpath="element"/>
> <xs:field xpath="@id"/>
> </xs:key>
> </xs:element>
> <xs:element name="test" maxOccurs="unbounded">
> <xs:complexType>
> <xs:attribute name="ref"/>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> <xs:keyref name="kr" refer="k">
> <xs:selector xpath="test"/>
> <xs:field xpath="@ref"/>
> </xs:keyref>
> </xs:element>
> </xs:schema>
>
> Xerces seems to discard all the key defined on "child" elements except the
> ones defined on the last "child" element, in the example only the "a1" and
> "a4" values are used when the keyref is checked.
>
> Saxon EE keeps all the key values, each set on its key space (that is each
> "child" element) and it triggers an error on the reference to a key that is
> defined in both "child" elements, the reference to "a1".
>
> My feeling is that Xerces is wrong and Saxon is correct but as I mentioned
> I cannot identify in the specification the relevant sections for this
> situation.
>
> Here there are the errors reported by Saxon
>
> System ID: /Users/george/Documents/test/**validation/instance1.xml
> Main validation file: /Users/george/Documents/test/**
> validation/instance1.xml
> Schema: /Users/george/Documents/test/**validation/test.xsd
> Engine name: Saxon-EE 9.4.0.6
> Severity: fatal
> Description: More than one referenced value found for keyRef {kr}
> "a1"
> Start location: 9:27
>
> System ID: /Users/george/Documents/test/**validation/instance1.xml
> Main validation file: /Users/george/Documents/test/**
> validation/instance1.xml
> Schema: /Users/george/Documents/test/**validation/test.xsd
> Engine name: Saxon-EE 9.4.0.6
> Severity: fatal
> Description: More than one referenced value found for keyRef {kr}
> "a1"
> Start location: 10:36
>
> System ID: /Users/george/Documents/test/**validation/instance1.xml
> Main validation file: /Users/george/Documents/test/**
> validation/instance1.xml
> Schema: /Users/george/Documents/test/**validation/test.xsd
> Engine name: Saxon-EE 9.4.0.6
> Severity: fatal
> Description: More than one referenced value found for keyRef {kr}: "a1"
> Start location: 5:0
>
> and here it is the error reported by Xerces:
>
> System ID: /Users/george/Documents/test/**validation/instance1.xml
> Main validation file: /Users/george/Documents/test/**
> validation/instance1.xml
> Schema: /Users/george/Documents/test/**validation/test.xsd
> Engine name: Xerces
> Severity: error
> Description: cvc-identity-constraint.4.3: Key 'kr' with value 'a2' not
> found for identity constraint of element 'parent'.
> Start location: 14:10
> URL: http://www.w3.org/TR/**xmlschema-1/#cvc-identity-**constraint<http://www.w3.org/TR/xmlschema-1/#cvc-identity-constraint>
>
> Best Regards,
> George
> --
> George Cristian Bina
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com
>
>
--
Regards,
Mukul Gandhi
Received on Monday, 14 January 2013 16:16:08 UTC