Switch to full style
XML Schema tutorial
Post a reply

define UUID in your XSD schema

Wed Mar 18, 2009 10:59 pm

Define UUID in XSD schema :
You can use pattern restriction to define UUID as a type in your XSD schema. For example :
Code:
<element name="UUIDType"  >
                <simpleType>
                    <restriction base="ID">
                        <pattern
                            value
="[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}">
                        </pattern>
                    </restriction>
                </simpleType>
            </element>


This XSD snippet defines an XML element called "UUIDType" with a simple type consisting of a restriction of the ID data type. The restriction has a pattern value of "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}". This means that the "UUIDType" element must contain a string value that matches the given pattern. The pattern is a regular expression that defines a specific format for a UUID (Universally Unique Identifier). It must be composed of 8 hexadecimal characters, followed by a hyphen, then four more hexadecimal characters, another hyphen, then four more hexadecimal characters, another hyphen, then four more hexadecimal characters, and finally 12 more hexadecimal characters. This XSD snippet can be used to validate XML documents to ensure that the "UUIDType" element contains a valid UUID value.

This XSD snippet only defines the structure of the "UUIDType" element, it doesn't specify any rules or constraints on how many times the element can occur, where it can occur in the XML document, or what elements can come before or after it. If you want to specify these kind of rules, you would need to include the "UUIDType" element in a larger XSD schema that defines the overall structure of the XML document. Also, this XSD snippet only defines the pattern for the UUID, it does not check if the value is unique or not, if you need to check the uniqueness, you can create a complex type to validate it.


UUID contains five sets of hexadecimal numbers.



Post a reply
  Related Posts  to : define UUID in your XSD schema
 UUID as key     -  
 lesson1 : <schema> Element     -  
 Define template in C++     -  
 Define statement     -  
 Define new namespaces in C++     -  
 define final class     -  
 Define enum in java     -  
 how to Define abstract class in php     -  
 Define your own exception class     -  
 define a Class with a Method     -  

Topic Tags

XSD Elements