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

Unique and Substitution groups

From: Adam van den Hoven <avandenhoven@cucbc.com>
Date: Mon, 19 Jul 2004 15:43:47 -0700
To: XML Schema Development <xmlschema-dev@w3.org>
Message-ID: <BD219CB3.783F%avandenhoven@cucbc.com>

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>

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:extension base="xs:string">
        <xs:attribute ref="role" default="title"/>
  <xs:complexType name="Label" id="ComplexType.Label">
      <xs:restriction base="Title">
        <xs:attribute ref="role" fixed="label" use="prohibited"/>
  <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 name="paths">
      <xs:selector xpath="node"/>
      <xs:field xpath="@step"/>
  <xs:complexType name="NodeType">
      <xs:element ref="title" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="node" minOccurs="0" maxOccurs="unbounded"/>
    <xs:attribute name="step" type="xs:NMTOKEN"/>
  <xs:complexType name="LeafType">
      <xs:restriction base="NodeType">
          <xs:element ref="title" minOccurs="0" maxOccurs="unbounded"/>
        <xs:attribute name="step" type="xs:NMTOKEN"/>
  <xs:element name="directory" type="NodeType" substitutionGroup="node"/>
  <xs:element name="file" type="LeafType" substitutionGroup="node"/>

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:
    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?
Received on Monday, 19 July 2004 18:44:33 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:05 UTC