Constant keys in xsd schemas

112 views Asked by At

I have the following XSD schema (extract):

<xs:key name="type">
  <xs:selector xpath="./datatypes/struct|./datatypes/array" />
  <xs:field xpath="@type" />
</xs:key>
<xs:keyref name="typeref" refer="type">
  <xs:selector xpath="./function/parameter|./function/return|./gloabalVariable|./datatypes/struct/field|./datatypes/array" />
  <xs:field xpath="@typeref" />
</xs:keyref>

Explanation: I want to specify some types which I can refer in functions, variables and other types.

Now I want to refer to primitive types, which are not declared in the XML, but should be constant keys in the XSD schema to which can be referred to.

What I have tried (and does not work):

<xs:key name="type">
  <xs:selector xpath="./datatypes/struct|./datatypes/array" />
  <xs:field xpath="@type|'uint8'|'int32'|..." />
</xs:key>

How can I specify constant keys in XSD schemas?

1

There are 1 answers

0
martin On BEST ANSWER

What I came up with and works for me:

<xs:simpleType name="type">
  <xs:union memberTypes="primitiveType complexType" />
</xs:simpleType>
<xs:simpleType name="primitiveType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="int8" />
    <xs:enumeration value="uint8" />
    <xs:enumeration value="int16" />          
    <xs:enumeration value="uint16" /> 
    <xs:enumeration value="int32" /> 
    <xs:enumeration value="uint32" /> 
    <xs:enumeration value="int64" /> 
    <xs:enumeration value="uint64" /> 
    <xs:enumeration value="double" /> 
    <xs:enumeration value="float" /> 
    <xs:enumeration value="string" /> 
    <xs:enumeration value="bool" /> 
  </xs:restriction>
</xs:simpleType>
<xs:simpleType name="complexType">
  <xs:restriction base="xs:IDREF" />
</xs:simpleType>