Named simpleType with string restriction and *pattern*. This sT basicType is applied to multiple elements. The catch is that two of these elements require type change to base="xs:ID".
This can be done by creating unique sT's: one sT for the fields that utilize the basic *pattern* restriction and another sT for the two fields requiring the ID base. Issue is that the pattern has to be duplicated in both sT declarations. It's a nit in my app but I wanted to learn if another approach was available. Specifically, one that would allow the pattern to be inherited and thus not duplicated for all the usual reasons. BTW: any alternative XSD 1.0 approach is OK. I'm not intending to restrict this to simpleType solutions only.
What I'd like to do is have a single pattern sT that can be applied to non-ID fields and have another derived sT that adds the ID base for the fields requiring ID while inheriting the pattern of the other sT. Thus, pattern is defined and maintained in one place only.
FWIW, this is a MSXML6 Excel app.
The following code snippet shows that the pattern is duplicated in each of the sT's.
Q) How to streamline this process?
<xs:simpleType name="basicType">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z]([A-Z0-9;-]){1,8}">
<!-- Upper case A~Z followed by 1~8, upper-case alphanumerics including hyphen. No whitespace. -->
</xs:pattern>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="IDType">
<xs:restriction base="xs:ID">
<xs:pattern value="[A-Z]([A-Z0-9;-]){1,8}"/>
</xs:restriction>
</xs:simpleType>
Note that
xs:IDandxs:IDREFare legacy types that stem from DTD.Your problem is a good case for XML Schema identity constraints. They are decoupled from the type hierarchy, and allow you to independently describe referential relationships between nodes.
In a schema, identity constraints are declared with
xs:keyelements, which mark the key nodes (=ID), andxs:keyrefelements, which mark nodes that reference keys (=IDREF).Take this simple document for example:
It can be described with the following schema. Note that
basicTypeis only declared once and can be used for all nodes, whether they are simple elements, or key attributes: