multi-field key/keyref fails to contrain?
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 2
- Joined: Tue Nov 09, 2004 11:18 pm
- Location: TN
multi-field key/keyref fails to contrain?
Post by DazedAndConfused »
Please tell me if I am missing something here. I have a schema with a 2-field key and also a keyref. These are defined at the scope of their common predecessor. The below schema validates with the below instance, when no proper pair of (1,2) exists. Is this a bug or am I thinking wrongheadedly? Thanks.
SCHEMA:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="ConstraintScope">
<xs:complexType>
<xs:sequence>
<xs:element name="Path1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Key1" type="xs:integer"/>
<xs:element name="Key2" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Path2Parent">
<xs:complexType>
<xs:sequence>
<xs:element name="Path2Child" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="FKey1" type="xs:integer"/>
<xs:element name="FKey2" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="Path1Keys">
<xs:selector xpath="Path1"/>
<xs:field xpath="Key1"/>
<xs:field xpath="Key2"/>
</xs:key>
<xs:keyref name="Path2KeyRef" refer="Path1Keys">
<xs:selector xpath="Path2Parent/Path2Child"/>
<xs:field xpath="FKey1"/>
<xs:field xpath="FKey2"/>
</xs:keyref>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
INSTANCE DOC:
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="KeyConstraints.xsd">
<ConstraintScope>
<Path1>
<Key1>1</Key1>
<Key2>1</Key2>
</Path1>
<Path1>
<Key1>2</Key1>
<Key2>2</Key2>
</Path1>
<Path2Parent>
<Path2Child>
<FKey1>1</FKey1>
<FKey2>2</FKey2>
</Path2Child>
<Path2Child>
<FKey1>2</FKey1>
<FKey2>2</FKey2>
</Path2Child>
</Path2Parent>
</ConstraintScope>
</Root>
The first Path2Parent/Path2Child sequence should not validate should it?!?
SCHEMA:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="ConstraintScope">
<xs:complexType>
<xs:sequence>
<xs:element name="Path1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Key1" type="xs:integer"/>
<xs:element name="Key2" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Path2Parent">
<xs:complexType>
<xs:sequence>
<xs:element name="Path2Child" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="FKey1" type="xs:integer"/>
<xs:element name="FKey2" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="Path1Keys">
<xs:selector xpath="Path1"/>
<xs:field xpath="Key1"/>
<xs:field xpath="Key2"/>
</xs:key>
<xs:keyref name="Path2KeyRef" refer="Path1Keys">
<xs:selector xpath="Path2Parent/Path2Child"/>
<xs:field xpath="FKey1"/>
<xs:field xpath="FKey2"/>
</xs:keyref>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
INSTANCE DOC:
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="KeyConstraints.xsd">
<ConstraintScope>
<Path1>
<Key1>1</Key1>
<Key2>1</Key2>
</Path1>
<Path1>
<Key1>2</Key1>
<Key2>2</Key2>
</Path1>
<Path2Parent>
<Path2Child>
<FKey1>1</FKey1>
<FKey2>2</FKey2>
</Path2Child>
<Path2Child>
<FKey1>2</FKey1>
<FKey2>2</FKey2>
</Path2Child>
</Path2Parent>
</ConstraintScope>
</Root>
The first Path2Parent/Path2Child sequence should not validate should it?!?
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
<oXygen/> uses the latest Xerces (2.6.2) for validating XML documents against XML Schemas. The problem you encountered is a known issue [1] and it was already resolved in Xerces CVS. I compiled the current CVS version and uploaded the xercesImpl jar [2] on our website so you can replace the one from oXygen with this one in order to get this fix.
[1] http://nagoya.apache.org/jira/browse/XERCESJ-1000
[2] http://www.oxygenxml.com/update/xercesImpl.jar
Best Regards,
George
<oXygen/> uses the latest Xerces (2.6.2) for validating XML documents against XML Schemas. The problem you encountered is a known issue [1] and it was already resolved in Xerces CVS. I compiled the current CVS version and uploaded the xercesImpl jar [2] on our website so you can replace the one from oXygen with this one in order to get this fix.
[1] http://nagoya.apache.org/jira/browse/XERCESJ-1000
[2] http://www.oxygenxml.com/update/xercesImpl.jar
Best Regards,
George
-
- Posts: 2
- Joined: Tue Nov 09, 2004 11:18 pm
- Location: TN
-
- Posts: 2
- Joined: Wed Mar 09, 2005 3:18 pm
Identity Constraint error: key out of scope
Post by reto.koenig »
After having bought the Oxygen5.1 License, I tried to create a simple schema and according to it an xml-file. But I always got the same error:
Identity Constraint error: identity constraint "KeyRef@..." has a keyref which refers to a key or unique that is out of scope
But validated with XML-Spy it said: This dokument is valid.
So where am I missing a point?
Schema:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:import namespace="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="xsi.xsd"/>
<xs:element name="SchoolScheduler">
<xs:complexType>
<xs:sequence>
<xs:element ref="Lessons"/>
<xs:element ref="Teachers"/>
<xs:element ref="Timeblocks"/>
</xs:sequence>
<xs:attribute ref="xsi:noNamespaceSchemaLocation" use="required"/>
</xs:complexType>
<xs:key name="timeblockKey">
<xs:selector xpath="./Timeblocks/Timeblock"/>
<xs:field xpath="@from"/>
</xs:key>
<xs:key name="teacherKey">
<xs:selector xpath="./Teachers/Teacher"/>
<xs:field xpath="@name"/>
</xs:key>
</xs:element>
<xs:element name="Lessons">
<xs:complexType>
<xs:sequence>
<xs:element ref="Lesson"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Lesson">
<xs:complexType>
<xs:attribute name="timeRef" type="xs:time" use="required"/>
<xs:attribute name="teacherRef" type="xs:string" use="required"/>
</xs:complexType>
<xs:keyref name="lessonTimeRef" refer="timeblockKey">
<xs:selector xpath="."/>
<xs:field xpath="@timeRef"/>
</xs:keyref>
<xs:keyref name="lessonTeacherRef" refer="teacherKey">
<xs:selector xpath="."/>
<xs:field xpath="@teacherRef"/>
</xs:keyref>
</xs:element>
<xs:element name="Teachers">
<xs:complexType>
<xs:sequence>
<xs:element ref="Teacher"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Teacher">
<xs:complexType>
<xs:attribute name="name" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="Timeblocks">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Timeblock"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Timeblock">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:time"/>
</xs:sequence>
<xs:attribute name="from" use="required" type="xs:time"/>
</xs:complexType>
</xs:element>
</xs:schema>
xml-Sample:
<?xml version="1.0" encoding="UTF-8"?>
<SchoolScheduler xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="2005-small.xsd">
<Lessons>
<Lesson timeRef="08:20:00" teacherRef="Alain Rohr"/>
</Lessons>
<Teachers>
<Teacher name="Alain Rohr"/>
</Teachers>
<Timeblocks>
<Timeblock from="08:20:00">
<to>09:15:00</to>
</Timeblock>
<Timeblock from="09:20:00">
<to>10:00:00</to>
</Timeblock>
</Timeblocks>
</SchoolScheduler>
Identity Constraint error: identity constraint "KeyRef@..." has a keyref which refers to a key or unique that is out of scope
But validated with XML-Spy it said: This dokument is valid.
So where am I missing a point?
Schema:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:import namespace="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="xsi.xsd"/>
<xs:element name="SchoolScheduler">
<xs:complexType>
<xs:sequence>
<xs:element ref="Lessons"/>
<xs:element ref="Teachers"/>
<xs:element ref="Timeblocks"/>
</xs:sequence>
<xs:attribute ref="xsi:noNamespaceSchemaLocation" use="required"/>
</xs:complexType>
<xs:key name="timeblockKey">
<xs:selector xpath="./Timeblocks/Timeblock"/>
<xs:field xpath="@from"/>
</xs:key>
<xs:key name="teacherKey">
<xs:selector xpath="./Teachers/Teacher"/>
<xs:field xpath="@name"/>
</xs:key>
</xs:element>
<xs:element name="Lessons">
<xs:complexType>
<xs:sequence>
<xs:element ref="Lesson"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Lesson">
<xs:complexType>
<xs:attribute name="timeRef" type="xs:time" use="required"/>
<xs:attribute name="teacherRef" type="xs:string" use="required"/>
</xs:complexType>
<xs:keyref name="lessonTimeRef" refer="timeblockKey">
<xs:selector xpath="."/>
<xs:field xpath="@timeRef"/>
</xs:keyref>
<xs:keyref name="lessonTeacherRef" refer="teacherKey">
<xs:selector xpath="."/>
<xs:field xpath="@teacherRef"/>
</xs:keyref>
</xs:element>
<xs:element name="Teachers">
<xs:complexType>
<xs:sequence>
<xs:element ref="Teacher"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Teacher">
<xs:complexType>
<xs:attribute name="name" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="Timeblocks">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Timeblock"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Timeblock">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:time"/>
</xs:sequence>
<xs:attribute name="from" use="required" type="xs:time"/>
</xs:complexType>
</xs:element>
</xs:schema>
xml-Sample:
<?xml version="1.0" encoding="UTF-8"?>
<SchoolScheduler xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="2005-small.xsd">
<Lessons>
<Lesson timeRef="08:20:00" teacherRef="Alain Rohr"/>
</Lessons>
<Teachers>
<Teacher name="Alain Rohr"/>
</Teachers>
<Timeblocks>
<Timeblock from="08:20:00">
<to>09:15:00</to>
</Timeblock>
<Timeblock from="09:20:00">
<to>10:00:00</to>
</Timeblock>
</Timeblocks>
</SchoolScheduler>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
While in the case of DTD the scope of the ID and IDREF/IDREFS is the whole document the XML Schema allows the scope to be restricted to an element. Moving the keyref from Lesson to SchoolScheduler where you have also the key should make them in the same scope. Also please note that there is no need to import a schema for the schema instance namespace and to define the xsi:noNamespaceSchemaLocation attribute.
The final schema is:
HTH,
George
While in the case of DTD the scope of the ID and IDREF/IDREFS is the whole document the XML Schema allows the scope to be restricted to an element. Moving the keyref from Lesson to SchoolScheduler where you have also the key should make them in the same scope. Also please note that there is no need to import a schema for the schema instance namespace and to define the xsi:noNamespaceSchemaLocation attribute.
The final schema is:
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:element name="SchoolScheduler">
<xs:complexType>
<xs:sequence>
<xs:element ref="Lessons"/>
<xs:element ref="Teachers"/>
<xs:element ref="Timeblocks"/>
</xs:sequence>
</xs:complexType>
<xs:key name="timeblockKey">
<xs:selector xpath="./Timeblocks/Timeblock"/>
<xs:field xpath="@from"/>
</xs:key>
<xs:key name="teacherKey">
<xs:selector xpath="./Teachers/Teacher"/>
<xs:field xpath="@name"/>
</xs:key>
<xs:keyref name="lessonTimeRef" refer="timeblockKey">
<xs:selector xpath="Lessons/Lesson"/>
<xs:field xpath="@timeRef"/>
</xs:keyref>
<xs:keyref name="lessonTeacherRef" refer="teacherKey">
<xs:selector xpath="Lessons/Lesson"/>
<xs:field xpath="@teacherRef"/>
</xs:keyref>
</xs:element>
<xs:element name="Lessons">
<xs:complexType>
<xs:sequence>
<xs:element ref="Lesson"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Lesson">
<xs:complexType>
<xs:attribute name="timeRef" type="xs:time" use="required"/>
<xs:attribute name="teacherRef" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="Teachers">
<xs:complexType>
<xs:sequence>
<xs:element ref="Teacher"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Teacher">
<xs:complexType>
<xs:attribute name="name" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="Timeblocks">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Timeblock"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Timeblock">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:time"/>
</xs:sequence>
<xs:attribute name="from" use="required" type="xs:time"/>
</xs:complexType>
</xs:element>
</xs:schema>
George
-
- Posts: 2
- Joined: Wed Mar 09, 2005 3:18 pm
Post by reto.koenig »
Hey George
You were perfectly right! That's exactly where I went wrong!
Thank you very much...
(I have to admit to myself, that a fool with a tool* is still a fool
)
*(Even if the tool is almost fool-proof)
You were perfectly right! That's exactly where I went wrong!
Thank you very much...
(I have to admit to myself, that a fool with a tool* is still a fool

*(Even if the tool is almost fool-proof)
-
- Posts: 1
- Joined: Mon Jun 20, 2005 11:18 am
- Contact:
Hi George,
I downloaded the last Xerces implementation form their CVS and build it, but <oXygen/> doesn't like it and complains with this message.
Do you have an idea how this problem can be resolved?
Best regards,
Emil.
The problem still persists. I downloaded <oXygen/> 6.0 build 2005051805 and it doesn't catch the situation described in the first post in this topic. Unfortunately the link that you gave to xercesImpl.jar file is not working anymore.<oXygen/> uses the latest Xerces (2.6.2) for validating XML documents against XML Schemas. The problem you encountered is a known issue [1] and it was already resolved in Xerces CVS. I compiled the current CVS version and uploaded the xercesImpl jar [2] on our website so you can replace the one from oXygen with this one in order to get this fix.
[1] http://nagoya.apache.org/jira/browse/XERCESJ-1000
[2] http://www.oxygenxml.com/update/xercesImpl.jar
I downloaded the last Xerces implementation form their CVS and build it, but <oXygen/> doesn't like it and complains with this message.
Do you have an idea how this problem can be resolved?
Best regards,
Emil.
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service