I would like to continue this thread because I really need to understand the specification of key/keyrefs and their selectors.
I need to create in some way a recursive mechanism. I am posting you a short schema example:
< xml version="1.0" encoding="UTF-8" >
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Book" type="Book_CT"> <xs:key name="ChapterKey"> <xs:selector xpath="Chapter"/> <xs:field xpath
"/> </xs:key> <xs:keyref name="ChapterKeyRef" refer="ChapterKey"> <xs:selector xpath="TOC"/> <xs:field xpath="Chapter"/> </xs:keyref> </xs:element> <xs:complexType name="Book_CT"> <xs:sequence> <xs:element name="Title" type="xs:string"/> <xs:element name="Author" type="xs:string"/> <xs:element name="TOC" type="TOC_CT"/> <xs:element name="Chapter" type="Chapter_CT"/> </xs:sequence> </xs:complexType> <xs:complexType name="Chapter_CT"> <xs:sequence minOccurs="0"> <xs:element name="Chapter" type="Chapter_CT" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="Name" type="xs:string" use="required"/> </xs:complexType> <xs:complexType name="TOC_CT"> <xs:sequence> <xs:element name="Chapter" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:schema>
And the correspondent XML project
< Book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..\..\Desktop\Untitled1.xsd"> <Title/> <Author/> <TOC> <Chapter>Chapter 1</Chapter> </TOC> <Chapter Name="Chapter 1"> <Chapter Name="Chapter 2.1"/> <Chapter Name="Chapter 2.2"> <Chapter Name="Chapter 2.2.1"/> </Chapter> </Chapter> </Book>
This example works, but not in the way I like.
The problem is that the definition
<xs:key name="ChapterKey">
<xs:selector xpath="//Chapter"/>
<xs:field xpath
"/>
</xs:key>
is not accepted by Altova. Is a problem of Altova, or the XML Schema specification do not allow this
|