Model XSD

Return to Introduction  Previous page  Next page

XML schemas are modeled using UML Class diagrams. The XML Schema pages of the Enterprise Architect UML Toolbox provide in-built support for the UML profile for XSD. This enables an abstract UML class model to be automatically generated as a W3C XML Schema (XSD) file.

The Class diagram below models simple schema for an example Employee Details system, intended to store a company's employee contact information. The classes shown form the EmployeeDetails package. The UML attributes of the classes map directly to XML elements or attributes. Note that the classes have no methods, since there is no meaningful correspondence between class methods and XSD constructs.


The following figure shows the schema generated for the Employee Details package by default. Notice how each UML class corresponds to a complexType definition in the schema. The class attributes are generated as schema elements contained in a Sequence model group within the definition. The Enumeration class is the exception here - it maps directly to an XSD enumeration, contained within a simpleType definition.


<?xml version="1.0"?>

<xs:schema xmlns:xs="">

       <xs:element name="ContactInfo" type="ContactInfo"/>

       <xs:complexType name="ContactInfo">


                       <xs:element name="ContactInfo.homePhone" type="xs:string" maxOccurs="1"/>

                       <xs:element name="" type="xs:string" maxOccurs="3"/>

                       <xs:element name="ContactInfo.streetAddress" type="xs:string"/>


                               <xs:element name="ContactInfo.mobilePhone" type="xs:string"/>

                               <xs:element name="ContactInfo.officePhone" type="xs:string"/>




       <xs:simpleType name="Gender">

               <xs:restriction base="xs:string">

                       <xs:pattern value="male|female"/>



       <xs:element name="Employee" type="Employee"/>

       <xs:complexType name="Employee">


                       <xs:extension base="Person">


                                       <xs:element name="status" type="Status"/>

                                       <xs:element name="jobTitle" type="xs:string"/>

                                       <xs:element name="startDate" type="xs:date"/>

                                       <xs:element name="department" type="xs:string"/>





       <xs:element name="Person" type="Person"/>

       <xs:complexType name="Person">


                       <xs:element name="surName" type="xs:string" maxOccurs="1"/>

                       <xs:element name="firstName" type="xs:string" maxOccurs="1"/>

                       <xs:element name="birthDate" type="xs:string" maxOccurs="1"/>

                       <xs:element name="contactDetails" type="ContactInfo"/>


               <xs:attribute name="gender" use="optional" type="Gender"/>


       <xs:element name="EmployeeRecords" type="EmployeeRecords"/>

       <xs:complexType name="EmployeeRecords">


                       <xs:element name="Employee" type="Employee" minOccurs="0" maxOccurs="unbounded"/>



       <xs:simpleType name="Status">

               <xs:restriction base="xs:string">

                       <xs:enumeration value="Full-Time"/>

                       <xs:enumeration value="Part-Time"/>

                       <xs:enumeration value="Casual"/>

                       <xs:enumeration value="Contract"/>





The following topics provide further explanation: