How to add a GUID simpleType into an XML schema?

guid, types, xml, xsd

Solution

You can define your own custom simple type "GUID" by restricting a string using a regular expression like this:

<xs:simpleType name="GUID">
  <xs:restriction base="xs:string">
    <xs:pattern value="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})|(\{[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\})"/>
  </xs:restriction>
</xs:simpleType>

Problem

I'm trying to create an XML schema, which enables an attribute value to be stored as an GUID in native format. I could set it up as a string, but it would be nice to store it as a real GUID. Any ideas how to do it?

Original source

Related problems