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?
A GUID is a 128bit identifier and normally fully random. Depending on the language you are using there are several functions to generate a GUID.
The line above: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tells the XML parser that this document should be validated against a schema. The line: xsi:noNamespaceSchemaLocation="shiporder. xsd" specifies WHERE the schema resides (here it is in the same folder as "shiporder. xml").
To edit a fileSelect the Use XML editor to view and edit the underlying XML Schema file link on the Start View. The XML editor appears with the new file open. Copy the XML Schema sample code from Purchase order schema and paste it to replace the code that was added to the new XSD file by default.
Reference the XSD schema in the XML document using XML schema instance attributes such as either xsi:schemaLocation or xsi:noNamespaceSchemaLocation. Add the XSD schema file to a schema cache and then connect that cache to the DOM document or SAX reader, prior to loading or parsing the XML document.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With