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?
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?
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>
XML basically contains only strings, although XSD also defines certain other primitive types. GUID, however, is not among them.
You can define your own schema for a GUID type. Lots of people have done this. Here's how the Microsoft OneNote team did it: http://msdn.microsoft.com/en-us/library/aa203890(office.11).aspx.
I've sussed it out. Sometimes it helps to read the docs. This is how it will work.
<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>
<xs:element name="ruleident">
<xs:complexType>
<xs:attribute name="ruleGuid" >
<xs:simpleType>
<xs:restriction base ="GUID"/>
</xs:simpleType>
</xs:attribute >
</xs:complexType >
</xs:element>