Skip to topic | Skip to bottom

Tesi.SchemaPathSyntaxr1.5 - 03 Apr 2006 - 16:24 - FabioVitalitopic end

Start of topic | Skip to actions

The Syntax of SchemaPath

SchemaPath is a light and minimal extension to XML Schema to add conditional assignment of types to its syntax. Conditions are expressed in terms of XPath expressions, and on the whole SchemaPath has exactly the same syntax of XML Schema (which you can find here and here). You can test a live implementation of our SchemaPath preprocessor in TestingSchemaPath.

SchemaPath adds to the XML Schema syntax exactly one new element and one new pre-defined simple type:

structure attributes description
<alt>   The <alt> element specifies conditions in the assignment of type to an element or attribute. With the presence of the element one signals the element or the attribute to be conditional
  cond An XPath specifying an expression to be evaluated for the condition to hold
  type The XML schema type to apply in case the condition holds. Both simple types and complex types can be specified
  priority An explicit priority for type assignment in case multiple conditions hold at the same time (much like priorities in XSLT templates)
xsd:error   A pre-defined simple type that cannot be satisfied: every assignment of the xsd:error to an element will yield a validation error. Use it for conditions that you do not want the document to satisfy

Use <alt> elements without a cond attribute for default conditions with low priority. Conditions for which there is no <alt> conditions are always false.

Some examples

Mutual exclusion

"Element x may have either the a attribute or the b attribute but not both". Suppose we have defined a type myType with both a and b attributes as optional
<xsd:element name="x">
   <xsd:alt cond="(@a and @b)" type="xsd:error"/>
   <xsd:alt                    type="myType"/>

Data-dependent structures

"The element quantity must be an integer if the unit element is ‘items’, and it must be a decimal value if the unit element is ‘meters’". Suppose we have already defined the data type for the unit element to only contain the values "meters" or "items".

<xsd:element name="quantity">
   <xsd:alt cond="../unit=‘items’"  type="xsd:integer"/>
   <xsd:alt cond="../unit=‘meters’" type="xsd:decimal"/>

Deep exclusion (XHTML)

"a elements cannot contain other a elements" Suppose we have defined an inlineType to contain all inline elements that can go inside an a element, as well as inside other elements such as b, i, etc.

<xsd:element name="a">
   <xsd:alt cond=".//a" type="xsd:error"/>
   <xsd:alt             type="inlineType"/>

Minimal presence (XSLT)

"In a template element at least one of the match and name attribute must be present" Suppose we have already defined a templateType type with the match and name attributes both set as optional

<xsd:element name="template">
   <xsd:alt cond="@match or @name" type="templateType"/>
   <xsd:alt                        type="xsd:error"/>

Complex mutual exclusions (XML Schema)

"An element definition must either contain a ref or a name attribute, but not both. Furthermore, if the name attribute is present, then either the type attribute or one of the simpleType or complexType elements must be present." Suppose we have already defined an elementType with a choice of simpleType and complexType, and the type, ref and name attributes as optional.
<xsd:element name="element">
    <xsd:alt cond="@name and @ref"                                  priority="2.0" type="xsd:error"/>
    <xsd:alt cond="(@type or @ref) and (simpleType or complexType)" priority="1.5" type="xsd:error"/>
    <xsd:alt cond="../schema and @ref"                              priority="1.0" type="xsd:error"/>
    <xsd:alt cond="not(@name) and not(@ref)"                        priority="0.5" type="xsd:error"/>
    <xsd:alt                                                        priority="0.0" type="elementType"/>
The conditions could be simpler by using different complex types

-- FabioVitali - 19 May 2004
to top

You are here: Tesi > TestingDTDPlusPlus > SchemaPathSyntax

to top

Copyright © 1999-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Fabio's Wiki? Send feedback