ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index
Contents > Unique and key

Unique and key

Uniqueness

We will use "unique" element to define, that the elements "a" under "root" element must have unique value of "id" attribute.

There is no such mechanism in Relax NG, but we can combine Relax NG and Schematron schemas.

...
Key

We will use "key" element to define, that the elements "a" under "root" element must have unique value of "id" attribute and it must be present.

There is no such mechanism in Relax NG, but we can combine Relax NG and Schematron schemas.

...
Uniqueness - comparison of numbers

In all checkings of "key", "unique", and "keyref" the values are compared, not string-values.

Schematron uses XPath functions, so we can force the conversion to a number.

...
Key and nillable

We will use "key" element to define, that the elements "a" under "root" element must have unique value of "id" element.

...
Unique and nillable

We will use "unique" element to define, that the elements "a" under "root" element must have unique value of "id" element. "Unique" does not require the value to exist, so the element can be "nil".

...
Keyref

The "keyref" lets you specify, that attribute/element refers to some node (which must be defined as "key" or "unique"). Now, the "key" element says: the elements "a" under "root" element must have unique value of "id" attribute and this attribute must be present. The "keyref" element specifies that element "b" refers to element "a" (via the attributes: b/@idref -> a/@id).

There is no such mechanism in Relax NG, but we can combine Relax NG and Schematron schemas.

...