Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Schema type alias?

Tags:

xml

w3c

xsd

Is there a way to define a type alias / strong typedef / simpleType with an empty restriction in XSD?

<xsd:simpleType name="identifier">
  <xsd:restriction base="xsd:string">
    <xsd:pattern value="^[a-zA-Z_][a-zA-Z0-9_]*$" />
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="type">
  <xsd:restriction base="identifier" />
</xsd:simpleType>

I would like to later apply some validation logic on attributes of type "type" more specific than the one for attributes of type "identifier."

like image 224
Klemens Baum Avatar asked Apr 17 '13 17:04

Klemens Baum


1 Answers

Yes, it's quite legal to derive a type like this with an empty restriction. However, although the two types have the same value space, they are not synonyms. The derived type is substitutable for the base type, but not other way around. For example, in a schema-aware XSLT stylesheet, an element validated against the base type will not match a template rule that expects an instance of the derived type.

like image 148
Michael Kay Avatar answered Oct 11 '22 04:10

Michael Kay