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.

GenXSDStereotypeExample

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="http://www.w3.org/2001/XMLSchema">

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

       <xs:complexType name="ContactInfo">

               <xs:all>

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

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

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

                       <xs:choice>

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

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

                       </xs:choice>

               </xs:all>

       </xs:complexType>

       <xs:simpleType name="Gender">

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

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

               </xs:restriction>

       </xs:simpleType>

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

       <xs:complexType name="Employee">

               <xs:complexContent>

                       <xs:extension base="Person">

                               <xs:sequence>

                                       <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:sequence>

                       </xs:extension>

               </xs:complexContent>

       </xs:complexType>

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

       <xs:complexType name="Person">

               <xs:sequence>

                       <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:sequence>

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

       </xs:complexType>

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

       <xs:complexType name="EmployeeRecords">

               <xs:all>

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

               </xs:all>

       </xs:complexType>

       <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"/>

               </xs:restriction>

       </xs:simpleType>

</xs:schema>

 

The following topics provide further explanation: