W3C home > Mailing lists > Public > xmlschema-dev@w3.org > July 2004

RE: Unique and Substitution groups

From: Michael Kay <mhk@mhk.me.uk>
Date: Tue, 20 Jul 2004 00:09:04 +0100
To: "'Adam van den Hoven'" <avandenhoven@cucbc.com>, "'XML Schema Development'" <xmlschema-dev@w3.org>
Message-Id: <20040719230939.A8B21A1535@frink.w3.org>

Writing <xs:selector xpath="node"/> where node is an abstract element isn't
going to work. XML Schema uses a subset of XPath 1.0, which isn't
schema-aware, so "node" takes the XPath 1.0 meaning - it matches an element
whose name is "node" (and there are no such elements).

Presumably XML Schema will one day support XPath 2.0, and you will then be
able to write xpath="element(node)", which matches any element in the
substitution group of "node". 

Michael Kay 

> -----Original Message-----
> From: xmlschema-dev-request@w3.org 
> [mailto:xmlschema-dev-request@w3.org] On Behalf Of Adam van den Hoven
> Sent: 19 July 2004 23:44
> To: XML Schema Development
> Subject: Unique and Substitution groups
> 
> 
> I trust all of you are having as pleasantly challenging a day as I am.
> 
> I'm writing a relatively complex Schema and this is going to 
> be the first
> time I am going to define any uniqueness checks. I'm also 
> making extensive
> use of abstract elements and substitution groups. Right now 
> I'm not 100%
> sure how those two behave together. I would like to think 
> that they behave
> as you would expect but I'm looking for confirmation.
> 
> The XML I'm writing the schema looks something like:
> 
> <directory step="home">
>   <title>This is a Title</title>
>   <label>This is a Label</label>
>   <directory step="dir1">
>     <title>Another Title</title>
>     <file step="AFile">
>       <title>File Title</title>
>     </file>
>   </directory>
> </directory>
> 
> In this schema, I want to make both <directory> and <file> 
> substitutions for
> an abstract element, which we can call node. This is the 
> schema I want to
> apply  to this document:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>   <xs:attribute name="role" type="xs:NMTOKEN"/>
>   <xs:complexType name="Title" id="ComplexType.Title">
>     <xs:simpleContent>
>       <xs:extension base="xs:string">
>         <xs:attribute ref="role" default="title"/>
>       </xs:extension>
>     </xs:simpleContent>
>   </xs:complexType>
>   <xs:complexType name="Label" id="ComplexType.Label">
>     <xs:simpleContent>
>       <xs:restriction base="Title">
>         <xs:attribute ref="role" fixed="label" use="prohibited"/>
>       </xs:restriction>
>     </xs:simpleContent>
>   </xs:complexType>
>   <xs:element name="title" type="Title"/>
>   <xs:element name="label" type="Label" substitutionGroup="title"/>
>   <xs:element name="node" abstract="true" type="NodeType">
>     <xs:key name="titlerole">
>       <xs:selector xpath="title"/>
>       <xs:field xpath="@role"/>
>     </xs:key>
>     <xs:key name="paths">
>       <xs:selector xpath="node"/>
>       <xs:field xpath="@step"/>
>     </xs:key>
>   </xs:element>
>   <xs:complexType name="NodeType">
>     <xs:sequence>
>       <xs:element ref="title" minOccurs="0" maxOccurs="unbounded"/>
>       <xs:element ref="node" minOccurs="0" maxOccurs="unbounded"/>
>     </xs:sequence>
>     <xs:attribute name="step" type="xs:NMTOKEN"/>
>   </xs:complexType>
>   <xs:complexType name="LeafType">
>     <xs:complexContent>
>       <xs:restriction base="NodeType">
>         <xs:sequence>
>           <xs:element ref="title" minOccurs="0" 
> maxOccurs="unbounded"/>
>         </xs:sequence>
>         <xs:attribute name="step" type="xs:NMTOKEN"/>
>       </xs:restriction>
>     </xs:complexContent>
>   </xs:complexType>
>   <xs:element name="directory" type="NodeType" 
> substitutionGroup="node"/>
>   <xs:element name="file" type="LeafType" substitutionGroup="node"/>
> </xs:schema>
> 
> My original question was about the use of <xs:key> in this 
> schema. Is it
> enough to simply define the constraints on the abstract 
> element and not
> bother worrying about it for the substituting elements.
> 
> In preparing this example, I started getting exceptions on 
> the LeafType
> delcaration. Namely, I'm being told:
> 
>     cos-particle-restrict.2: Forbidden particle restriction:
> 'choice:all,sequence,elt'.
>     derivation-ok-restriction.5.4.2: Error for type 'LeafType'.  The
> particle of the type is not a valid restriction of the 
> particle of the base.
> 
> Both errors refer to the LeafType complexType.
> 
> Any thoughts on either issue?
> Adam
> 
Received on Monday, 19 July 2004 19:09:39 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 07:15:10 UTC