UML to XSD Transformation

Table of Contents

Overview

This transformation accepts a UML package as its source and generates an XML Schema by converting the appropriate classes in the package into elements of the schema. The generated schema is stored in a folder named, schema, in a project you specify as the target of the transformation. The file containing the schema has a name same as the name of the package and has an extension .xsd.

For example, suppose you have a UML package called, PurchaseOrder that contains a class named, Address. When you run this transformation with this package as its source, it produces the following XML schema.

If you choose a UML model (that has at least one package) as the source, this transformation generates an XML schema for each package in the model that has a stereotype <<XSDProfile::schema>> or a keyword schema. The transformation generates an XML schema for each package, if you set the value of the transformation property, Process unmarked packages, to true.

Table of Contents

Exploring the example models

The software bundles a set of example UML models you can use as sources for the UML to XSD transformation. After you have installed the UML to XSD transformation, you will need to copy the examples from the install directory to your workspace. For example, if you have installed the software in RSA/eclipse, the examples will be in the folder RSA/eclipse/plugins/com.ibm.xtools.transform.samples.uml2.xsd/examples. Do the following to copy the examples in your workspace:

  1. Create a simple project: File > New > Project...  and select Simple > Project and click next.
  2. Give the project a name (say uml2xsd.examples) and click Finish.
  3. Copy the directory <install-dir>/rsa/eclipse/plugins/com.ibm.xtools.transform.uml2.xsd/examples where <install-dir> is where you installed Rational Software Development Platform.
  4. Open one or more models. Double-clicking on the models and packages will open the associated diagrams showing the models, the generated schema and the various stereotype properties and transformation properties used to generate the schema.

NOTE: When opening an example model you may get a dialog stating that the model is using an old version of the XSDProfile and asking you if you would like to migrate to the new profile. You should click Yes to migrate to the new version of the profile.

Table of Contents

Running the transformation

To run the transformation:

  1. In your workspace create a UML model that contains one or more packages. Create a few UML classes in each of the packages.
  2. Optionally, do the following:

    These steps are necessary if you want to create a UML model of a non-trivial XML schema. For more information on modeling XML schema in UML, see the section, Modeling XML Schema in UML: Good Practices.

  3. Switch to the Modeling perspective, if you are not already in the Modeling perspective.
  4. Right-click the model or a package; then click Transform > Run Transformation > UML to XSD.
  5. In the Run Transform window, on the Target page specify the project in which to write the output XSD schema files.
  6. Click Run.

The transformation generates the XSD schema and places them in the specified project in a folder named schema. Use a Navigator view to inspect the generated schema.

Table of Contents

Using the XSD template model

You can also create a UML model using the XSD template model. This has the advantage that the necessary model library, XSDDataTypes, is already imported and XSD profile is applied to the package(s).

  1. Create a UML model .
    1. File > New > Project >UML Project.
    2. In the UML Modeling Project dialog enter the project name and click Next.
    3. In the resulting dialog, select  XSD Model  and give an appropriate name for the model. (In your version of RSA/RSM, you may see two instances of XSD Model in Templates pane. This is a known defect which has been fixed in later versions of RSA/RSM. Choosing one of the two "XSD Model" items will work.)
    4. Click Finish.
  2. The newly created UML model is based on a model template and will have the necessary model libraries imported. You now need to create one or more packages. To do so:
    1. Open the package, XSD Model Building Block.
    2. Control-drag the package ${schema.name} and drop it on the root model.  This will create a package with the XSD Transformation profile already applied to it.
    3. Using Find/Replace change the name of the package from ${schema.name} to a more appropriate one.
    4. Populate the package with necessary UML classes.
  3. Switch to the Modeling perspective, if you are not already in the Modeling perspective.
    1. Right-click the model or a package; then click Transform > Run Transformation > UML to XSD.
    2. In the Run Transform window, on the Target page specify the project in which to write the output XSD schema files.
    3. Click Run.

The transformation generates the XSD schema and places them in the specified project in a folder named schema. Use a Navigator view to inspect the generated schema.

Table of Contents

Transformation details

Transformation source

This transformation accepts a UML model containing at least one package or one or more UML packages as the source.

Transformation target

This transformation accepts a project as its target.

Table of Contents

Transformation properties

This transformation defines the following transformation properties:

Property Description
Target Namespace The target namespace of the schema generated by the transformation. The value of this property is a string, such as, http://www.ibm.com/SampleXSDTransformation.
Target Namespace Prefix The prefix for the target namespace of the schema generated by the transformation. The value of this property is a string, such as, sxt.
Process UML class without stereotype or keyword

This property determines if the transformation processes a UML class if the class does not have any stereotype or keyword associated with it.

The value of this property can be either true or false. By default its value is set to true and the transformation processes all classes in a top-level package. (Currently the transformation does not handle nested packages.)

If you do not need to apply the transformation to all the classes in a package, you need to set its value to false and apply appropriate stereotypes from the XSDProfile or keywords to the classes you want to transform.

Process UML package without stereotype or keyword

This property determines if the transformation processes a UML package if the package does not have any stereotype or keyword associated with it.

The value of this property can be either true or false. By default its value is set to true and the transformation processes all top-level packages. (Currently the transformation does not handle nested packages.)

If you do not need to apply the transformation to all top-level packages in a model, you need to set its to false and apply appropriate stereotype <<schema>> from the XSDProfile or the keyword schema to the packages you want to transform.

Convert a nested class to anonymous type implicitly

This property determines if the transformation converts a nested class into an anonymous type when there is no explicit association between the nesting class and the nested class.

The value of this property can be either true or false. By default its value is set to false and the transformation converts a nested class into an anonymous type only if there is an association to it from the nesting class. If its value is set to true, all nested classes are converted into anonymous types with the XSD types corresponding to the nested classes containing elements whose types are these anonymous types.

Generation of anonymous types implicitly by setting the value of this property to true has several limitations and hence we recommend that you use it very sparingly.

Table of Contents

XSD profile

The modeling of a non-trivial XML schema in UML supported by the UML to XSD transformation uses a small subset of UML constructs to represent the XML schema elements. This subset includes the following UML elements: class, property, generalization, association, and dependency. To represent the XML schema elements, such as, simple type, complex type, attribute and element, reusable groups, etc., using this subset, you need to apply the XSD profile to the source UML model and mark it up using stereotypes from this profile and setting the properties of the stereotypes to appropriate values.

The following class diagram shows the UML model of the XSD profile.

The table below describes the stereotypes and their properties.

Stereotype Metaclass Extension Properties Comments
annotation Comment kind
language
source

The comment is converted into an application info or a documentation annotation.

The property kind determines the type of annotation: documentation and appinfo. The properties language and source specify the natural language of the documentation and source of further documentation respectively.

attribute Property (of Class) form
use

The UML property is converted into an attribute in a complex type or an attribute group if its type is a simple type and its multiplicity is [0..1].

The stereotype property form determines whether the attribute name must be qualified in the instance document. It value can be one of qualified or unqualified or default. If it is default, the value defaults to attributeFormDefault of schema which defaults to unqualified.

The property use determines whether the attribute is optional or required. Its value can be one of optional or prohibited or required.  By default its value is optional. The value prohibited is ignored in the current implementation.

attributeGroup Class
The class is converted into an attribute group.
complexType Class anonymous
block
final
modelGroup
maxOccurs
minOccurs
mixed

The class is converted into a complex type.

The property anonymous determines if a top-level complex type declaration is created in the schema. Its value can be either true or false. If it is true, no type declaration is generated and any reference to this class is converted into an attribute or element declaration with the anonymous type as the type of the attribute or element. By default its value is false.

The property block determines whether to block type substitution. It can have one of the following values: #all or extension or  restriction or a whitespace-separated list of extension and restriction. The value #all prevents any derived types from substituting for this type, extension prevents any extensions of this type from substituting for this type, and restriction prevents any restriction of this type from substituting for this type. The list, "extension restriction", has the same effect as #all. If no block property is specified, the value defaults to the blockDefault  property of the schema.

The property final determines whether other types can be derived from this one. Its value can be #all or a list of  (extension or restriction).  If its value is #all, derivation of any kind is disallowed. For more specific control, the value can be set to be a whitespace-separated list of any of the keywords restriction or extension . It defaults to finalDefault of schema.

The property modelGroup determines the content model of the type. The value of modelGroup can be all or choice or sequence. The default value is sequence.

Constraint: If the value of modelGroup is all, the value of anonymous must be set to false. Otherwise, a constraint violation will occur.

The values of minOccurs and maxOccurs determines the minimum and maximum number of times the sequence and choice group may occur in the complex type. For an all model group, maxOccurs must be 1 and minOccurs may only be 0 or 1.

The boolean property mixed specifies whether the complex type allows mixed content. By default its value is false.

element Property (of Class) block
final
form
nillable

The property is converted into an element.

The property final applies to only the global elements and not to local elements. It determines whether other types can be derived from this one. Its value can be #all or a list of  (extension | restriction).  If its value is #all, derivation of any kind is disallowed. For more specific control, the value can be set to be a whitespace-separated list of any of the keywords restriction or extension . It defaults to finalDefault of schema.

The stereotype property form determines whether the element name must be qualified in the instance document. It value can be one of qualified or unqualified or default. If it is default, the value defaults to elementFormDefault of schema which defaults to unqualified.

The boolean property nillable determines whether xsi:nil can be used in the instance for this element. By default its value is false.

enumeration Class anonymous

The class is converted to a XSD enumeration if the class has generalization relation to another class representing a simple type.

The property anonymous determines if a top-level simple type declaration with enumeration facets is created in the schema. Its value can be either true or false. If it is true, no type declaration is generated and any reference to this class is converted into an attribute or element declaration with the anonymous type as the type of the attribute or element. By default its value is false.

global Class

A class with this stereotype is converted into a top-level element or attribute declaration. The class must have only one property. If the property has a <<attribute>> stereotype or keyword, the class is converted into a top-level attribute. Otherwise, it becomes a top-level element.

The name of the element or the attribute is the same as the name of the property and the type is the  type of the property.

listOf Dependency
The client of the dependency is converted into an XSD list whose item type is the supplier of the dependency. There can be only one such dependency between two classes each representing a simple type.
modelGroup Class anonymous
modelGroup

The class is converted into a reusable named model group with a sequence content model.

The property anonymous determines if a top-level group declaration is created in the schema. Its value can be either true or false. If it is true, no group declaration is generated. and any reference to this class is converted into a nested model group. If the value is false, a reference to the class is converted into a model group reference. By default its value is false.

The property modelGroup determines the content model of the group. The value of modelGroup can be all or choice or sequence. The default value is sequence.

Constraint : If the value of modelGroup is all, the value of anonymous must be set to false. Otherwise, a constraint violation will occur.

schema Package attributeFormDefault
blockDefault
elementFormDefault
finalDefault
targetNamespace
targetNamespacePrefix

The package and its contents are converted into an XSD schema. The name of the package becomes the name of the schema (file).

The property attributeFormDefault specifies whether local attribute declarations should use qualified names. Its value can be either qualified or unqualified. The default value is unqualified.

The property  blockDefault sets the default value for the block attribute used in complex type and element declarations. The block attribute determines whether to block element substitution or type substitution. It can have the following values: #all or a whitespace-separated list of one or more of (extension or restriction or substitution).

The property elementFormDefault specifies whether local element declarations should use qualified names. Its value can be either qualified or unqualified. The default value is unqualified.

The property  finalDefault sets the default value for the final attribute used in complex type, simple type and element declarations. The final attribute determines whether to disallow type derivation. It can have the following values: #all or a whitespace-separated list of one or more of (extension or restriction or substitution or list or union).

If you set the values of targetNamespace and targetNamespacePrefix, these values will override those you may have set for the corresponding transformation properties, Target Namespace and Target Namespace Prefix respectively.

simpleType Class anonymous
final
fractionDigits
length
maxExclusive
maxInclusive
maxLength
minExclusive
minInclusive
minLength
pattern
totalDigits
whiteSpace

The class is converted into a simple type if the class has a generalization to an XSD built-in data type or another simple type or an XSD enumeration type.

The value of the property, anonymous, can be either true or false. If it is true, the class is treated as an anonymous type and no top-level type declaration is generated.

The property final determines whether other types can be derived from this one. Its value can be #all or a list of  (extension or restriction or list or union).  If its value is #all, derivation of any kind is disallowed. For more specific control, the value can be set to be a whitespace-separated list of any of the keywords restriction, extension, list, or union.

The rest of the properties represent the facets defined by the XSD schema. Using these facets, you can specify a valid range of values, constrain the length and precision of  values, specify a regular expression that valid values must match, or specify the processing of whitespace of simple types that are derived by restriction from built-in XSD types. For more details see the table, Meaning of the Facets.

Note that not all of these facets are applicable to all simple types. For example, for the simple types that are derived from string, normalizedString and token, the applicable facets are length, minLength, maxLengthpattern and whitespace. For more details see the table, Simple Types and Applicable Facets.

unionOf Dependency
The client of the dependency is converted into an XSD union with the supplier of the dependency as one of its member. A class representing a simple type can have more than one such dependency to different (simple type) classes.
wildcard Property (of Class) processContents
namespace

The UML property is converted into an element wildcard. If the property has the keyword, attribute or stereotype <<attribute>> in addtion to wildcard, it is converted into an attribute wildcard.

The property processContents determines how strictly to validate the replacement attributes or elements. If it is skip, the schema processor performs no validation. If it is lax, the schema processor will validate attributes or elements for which it can find declarations and raise errors if they are invalid. If it is strict, the schema processor will attempt to find a schema document associated with the namespace and validate all of the attributes or elements. By default its value is set to strict.

The property namespace specifies which namespace(s) the replacement attributes or elements may be in. The allowed value is one of  (##any, ##other, list of anyURI or ##targetNamespace or ##local). If it is ##any, the replacement elements or attributes can be in any namespace whatsoever, or be in no namespace. If it is ##other, the replacement elements or attributes can be in any namespace other than the target namespace of the document, but they must be in a namespace. If the schema document  has no target namespace, the replacement elements or attributes can have any namespace, but they must have one. Otherwise, it can be a whitespace-separated list of values which includes any or all of the following items: ##targetNamespace, #local or specific namespaces. ##targetNamespace indicates that the replacement elements or attributes may be in the target namespace of the schema document and ##local indicates that the replacement elements or attributes may be in no namespace.

Table of Contents

Keywords

If the schema you are modeling does not need to specify its elements in small details, you may want to use the keywords instead of the stereotypes. The following table describes the keywords supported by UML to XSD transformation.

Keyword Applicable to UML Element Comments
annotation Comment The comment is converted into an "appinfo" or a "documentation" annotation.
attribute Property (of Class) The property is converted into an attribute in a complex type if the multiplicity of the property is [0..1].
attributeGroup Class The class is converted into an attribute group.
complexType Class The class is converted into a complex type.
element Property The property is converted into an element of a complex type.
enumeration Class The class is converted to a XSD enumeration if the class has generalization relation to another class representing a simple type.
global Class

A class with this keyword is converted into a top-level element or attribute declaration. The class must have only one property. If the property has a <<attribute>> stereotype or a keyword, attribute, the class is converted into a top-level attribute. Otherwise, it becomes a top-level element.

The name of the element or the attribute is derived from the name of the property and the type is derived from the  type of the property.

listOf Dependency between two classes representing two simple types The client of the dependency is converted into an XSD list whose item type is the supplier of the dependency. There can be only one such dependency between two classes each representing a simple type.
modelGroup Class The class is converted into a reusable named model group with a sequence content model.
schema Package

The package and its contents are converted into an XSD schema. The name of the package becomes the name of the schema (file).

If you use keyword, schema, you will need to specify the target namespace and the target namespace prefix by setting the transformation properties, Target Namespace and Target Namespace Prefix respectively, to appropriate values.

simpleType Class The class is converted into a simple type if the class has a generalization to an XSD built-in data type or another simple type.
unionOf Dependency between two classes representing two simple types The client of the dependency is converted into an XSD union with the supplier of the dependency as one of its member. A class representing a simple type can have more than one such dependency to different (simple type) classes.
wildcard Property

The UML property is converted into an element wildcard. If the property has the keyword, attribute in addtion to wildcard, it is converted into an attribute wildcard.

Table of Contents

Model library: XSD built-in data types

Forty-four simple types are built into the XML Schema Recommendation. These simple types represent common data types such as strings, numbers, date and time values, and also include legacy types for the attribute types in XML 1.0. XSD also provides twelve constraining facets which you can use to specify a valid range of values of the simple types, constrain the length and precision of their values, enumerate a list of valid values, or specify a regular expression that valid values must match.

You can derive new simple types from the built-in types or other simple types by restricting them by setting the facets to appropriate values. To do so, it is necessary to have representation of the built-in types available in the UML models.

The built-in simple types are modeled as classes and made available in a model library called XSDDataTypes. You need to import the XSDDataTypes library in your model to access these types. To import the XSDDataTypes model library, in the Model Explorer Right-Click on the root of your model (the model itself), select Import Model Library..., and choose XSDDataTypes from the drop-down list.

To define new simple types (user-defined simple types) you need to specialize from appropriate classes in XSDDataTypes model and use the properties of the <<simpleType>> stereotype to constrain the value of the defined types. For example:

You can restrict the maximum value of Quantity to, say, 100 by setting the maxInclusive property of <<simpleType>> to 100.

Table of Contents

UML to XSD mapping rules

The purpose of modeling XML schema in UML is to create a visual representation of a XML schema and then generate the schema using a UML to XSD transformation. Analysis shows that most of the fundamental functionalities of XML schema can be represented by UML model elements. The following table shows a subset of the mapping between the concepts present in UML and the corresponding concepts in XML Schema Definition (XSD).

UML Concepts XML Schema Concepts
Package Single namespace with a prefix
Class Types and reusable groups
  • Complex type and matching element declaration
  • Simple type
  • Attribute group, named model group and substitution group
Enumeration Restriction of an XSD string simple type with enumeration facets equal to the UML enumeration literals. Note that this is different from what happens with a UML class that has the <<enumeration>> stereotype from XSD profile applied. Using a stereotyped UML class allows more general XSD enumerations.
Properties of a class Elements and attributes of a complex type
Association (Aggregation) Child element of a contained element (complex type)
Generalization Type derivation
  • Derivation by extension of complex type
  • Derivation by restriction of complex type
  • Derivation by restriction of simple type
Object Identity User specified key fields or an explicit identity mechanism (not yet implemented.

Mapping Rule: Package -> XSD Schema

UML Element XSD Element Comments
Package with stereotype <<schema>> Schema with a target namespace and target namespace prefix Contents inside a package make a schema in an .xsd file. The schema file's name is the same as that of the package.

The properties of the <<schema>> stereotype, attributeFormDefault, and elementFormDefault, can be used to specify the attributeFormDefault, and elementFormDefault attributes on the generated schema.

If you use the keyword, schema, instead of the stereotype, you should supply the target namespace and its prefix by setting the values of  transformation properties, Target Namespace and Target Namespace Prefix respectively.

Mapping Rules: Class -> Complex type, Property -> Element and Property -> Attribute

UML Element XSD Element Comments
Class with stereotype <<complexType>> Complex type If the stereotype property, modelGroup, is not set to one of the possible values, all, choice or sequence, the complex type is generated with a sequence model group.
Class with keyword complexType Complex type The complex type is generated with a sequence model group.
Class with no keyword or stereotype Complex type A complex type is generated only if the value of the transformation property, Process unmarked class, is set to true. Otherwise, the class is ignored. If a complex type is generated, its model group is set to sequence.
Property Element of the complex type
Property with <<attribute>> stereotype or a keyword, attribute. Attribute of the complex type

The property is converted to an attribute only if the type of the property is a simple type and it has a multiplicity of [0..1]. Otherwise, it is converted into an element.

If you provide a default value, the property is converted  into an optional attribute with a default value. If you make the property read only and provide a default value, it is converted into an attribute with its value fixed to the default. In both cases you need to set the multiplicity of the property to [0..1].

You can use the property, use, of the <<attribute>> stereotype to make the attribute optional, or required. If you set the value of use to required, as well as provide a default value and make the property read only, the default value and the read 0nly specification will be ignored.

Mapping Rule: Class with <<global>>  -> Global element or attribute

UML Element XSD Element Comments
A class with a stereotype <<global>> or a keyword "global" containing one property. Global (top-level) element or attribute.

The class must have only one property. If the property has a <<attribute>> stereotype or a keyword, attribute, the class is converted into a top-level attribute. Otherwise, it becomes a top-level element.

The name of the element or the attribute is derived from the name of the property and the type is derived from the  type of the property.


Mapping Rule: Generalization relationships among <<global>> classes -> Substitution group

UML Element XSD Element Comments
Generalization relatioships among classes that have the stereotype <<global>> applied. A substitution group composed of the global elements represented by the classes with <<global>> stereotypes. To form a substitution group of global elements their types (classes) themselves must be in an equivalent generalization relationship.

In the example below, the global element dress is the head of the substitution group and the global elements, shirt and trouser, are the members. Note that the types of these elements are in ageneralization relationship that is equivalent to the generalization relationship among the global elements.


Mapping Rule: Class -> Simple type

UML Element XSD Element Comments
Class with a stereotype <<simpleType>> or a keyword, simpleType

User defined simple type.

Restriction of a built-in simple type or another user defined simple type

Must have a generalization relationship to a built-in simple type or another user defined simple type or an XSD enumeration type.

Mapping Rule: Class -> XSD Enumeration

UML Element XSD Element Comments
Class with stereotype <<enumeration>> or keyword enumeration XSD enumeration.
A simple type with enumeration facet specified
Must have a generalization relationship to a built-in simple type or another user defined simple type.

Mapping Rule: UML Enumeration -> XSD Enumeration

UML Element XSD Element Comments
UML Enumeration XSD enumeration, a simple type with restriction base xsd:string and with enumeration facet specified Does not need any generalization to any other simple type.

Mapping Rules: Class -> Reusable groups: model group and attribute group

UML Element XSD Element Comments
Class with stereotype <<modelGroup>> Named model group If the stereotype property, modelGroup, is not set to one of the possible values, all, choice or sequence, the model group is generated with a sequence model group.
Class with keyword modelGroup Named model group The named model group is generated with a sequence model group.
Class with stereotype <<attributeGroup>> or with keyword attributeGroup Attribute group Each property of the class is converted into a member of the attribute group, provided it is of a type that can be converted into a simple type and has a multiplicity [0..1]. Otherwise, the property is ignored.

Since the properties can only be converted into XSD attributes, it is not strictly necessary to apply the stereotype <<attribute>> to the properties. If, however, you want to specify additional properties (such as required, form, etc.) for the attributes, you need to apply the <<attribute>> stereotype and set the stereotype's properties to appropriate values.

Mapping Rule: Class derivation

UML Element XSD Element Comments
Class A derives from another class B.

A complex type B that is a complex content extension of the complex type A.

Class A or class B can have a stereotype <<complexType>> or keyword, complexType.

Neither class A nor class B can have a "all" model group or content model. Attempt to extend classes with "all" model gcroups leads to violation of constraint.

Class B cannot have the stereotype <<modelGroup>> or <<attributeGroup>> nor can it have a keyword modelGroup or attributeGroup. In other words a complex type cannot extend a model group or an attribute group.

Class A derives from another class B with a <<simpleType>> stereotype or a  keyword, simpleType.

A complex type B that is a simple content extension of a simple type. Any property of class B becomes an attribute of the simple content extension.

The only purpose of deriving from a simple type is to add attributes. Hence, the type of a property of class B must be a simple type and its multiplicity of should be [0..1]. Otherwise, the model will violate constraint.

Mapping Rule: Association -> Complex type element

UML Element XSD Element Comments
Association (directed or composite aggregation) Class A -> Class B Element in complex type A of type complex type B Element name is determined by the role name of the association end.

Mapping Rule: Property -> Complex type element

UML Element XSD Element Comments
Class A contains one or more properties of type Class B Element in complex type A of type complex type B Element name is determined by the name of the property.

Mapping Rule: Association -> Model group reference and Attribute group reference

UML Element XSD Element Comments

Association (directed association or composite aggregation) from Class A to Class B with a <<modelGroup>> stereotype.

Class A -> Class C with <<attributeGroup>> stereotype.

Model group reference in complex type A.

Attribute group reference in complex type A.


Association (directed association or composite aggregation) from Class A with <<modelGroup>> stereotype to Class B also with  <<modelGroup>> stereotype A model group reference in the model group represented by Class A
Association (directed association or composite aggregation) from Class A with <<attributeGroup>> stereotype to Class B also with  <<attributeGroup>> stereotype An attribute group reference in the attribute group represented by Class A.



Mapping Rule: Dependency -> List and Union types

UML Element XSD Element Comments
Dependency with a stereotype <<listOf>> or a keyword listOf between two simple types

List type.

The client of the dependency is converted into a simple type that is a list of the supplier of the dependency

The client and supplier of the dependency must be both simple types and there must be only one <<listOf>> dependency between them. There should not be any other relationship between these two classes.

Dependency with a stereotype <<unionOf>> or a keyword unionOf between a client simple type and one or more suppliers Union type.

The client of the dependency is converted into a simple type that is a union of the suppliers of the dependency .

The client and the suppliers of the dependency must be both simple types and there can be one or more <<unionOf>> dependency between them. There should not be any other relationship between these classes.

Table of Contents

Mapping Rule: Class -> Anonymous complex type

UML Element XSD Element Comments

Class A with a stereotype <<complexType>> and stereotype property anonymous = true and is referenced by another class B representing a complex type.

Class A is converted  into an anonymous complex type.

The reference is converted into an element in the complex type (represented by class B). The type of the element is defined by this anonymous type.

Element name is determined by the role name of the association end or the property name.

Since the class A is specified as anonymous, no top-level complex type declaration is generated for this class.

Mapping Rule: Class -> Anonymous simple type

UML Element XSD Element Comments
Class A with a stereotype <<simpleType>> and stereotype property anonymous = true and is referenced by another class B representing a complex type

Class A is converted  into an anonymous simple type.

The reference is converted into an attribute or element in the complex type (represented by class B). The type of the element or attribute is defined by this anonymous type.

Element or attribute name is determined by the role name of the association end or the property name.

Since the class A is specified as anonymous, no top-level simple type declaration is generated for this class.

Mapping Rule: Class-> Anonymous enumeration

UML Element XSD Element Comments
Class A with a stereotype <<enumeration>> and stereotype property anonymous = true and is referenced by another class B representing a complex type

Class A is converted  into an anonymous enumeration.

The reference is converted into an attribute or element in the complex type (represented by class B). The type of the element or attribute is defined by this anonymous type.

Element or attribute name is determined by the role name of the association end or the property name.

Since the class A is specified as anonymous, no top-level simple type declaration with enumeration facet is generated for this class.

Mapping Rule: Reference to anonymous model group -> Nesting of sequence and choice groups

UML Element XSD Element Comments

Association (directed or composite aggregation) between a class A and a class B with a stereotype <<modelGroup>> and the value of property anonymous = true.

A complex type representing class A containing the model group of the named model group represented by class B.

This mapping is valid only if  neither A nor B has a content model all.
Association (directed or composite aggregation) between a class A with a stereotype <<modelGroup>> and a class B with a stereotype <<modelGroup>> and the value of property anonymous = true. A named model group  representing class A containing the model group of the named model group represented by class B. This mapping is valid only if  neither A nor B has a content model all.

The above reference to model groups can also be modeled using class properties.

UML Element XSD Element Comments
Class A containing a property whose type is class B with a stereotype <<modelGroup>> and the value of property anonymous = true. A complex type representing class A containing the model group of the named model group represented by class B. This mapping is valid only if  neither A nor B has a content model all.
Class A with a stereotype <<modelGroup>> containing a property whose type is class B with a stereotype <<modelGroup>> and the value of property anonymous = true. A named model group  representing class A containing the model group of the named model group represented by class B. This mapping is valid only if  neither A nor B has a content model all.

Mapping Rule: Nested Class -> Anonymous complex type

UML Element XSD Element Comments
Class A containing a nested class B with an association between A and B. Element in complex type A of an anonymous type B.

There must be an association between the nesting class and the nested class.

The same schema component is obtained if class A contains a property of type B instead of an association.



Mapping Rule: Nested Class -> Anonymous simple type

UML Element XSD Element Comments
Class A containing a nested class B with a stereotype <<simpleType>> or keyword, simpleType, and with an association between A and B. Element in complex type A of an anonymous simple type B.

There must be an association between the nesting class and the nested class.

The same schema component is obtained if class A contains a property of type B instead of an association.

Mapping Rule: UML Comment -> Annotation

UML Element XSD Element Comments
Comment Annotation A comment in a UML element is converted to an XSD documentation annotation.
Comment with <<annotation>> stereotype Annotation The type of annotation, documentation or appinfo, depends on the value of the kind property of the <<annotation>> stereotype. If the value of kind is A documentation element is created if the value of kind is documentation. An appinfo element is created if the value is applicationInfo. The default value of kind is documentation.




Mapping Rule: Property -> Element wildcard

UML Element XSD Element Comments
Property with a stereotype <<wildcard>> or keyword wildcard. Element wildcard in the enclosing complex type or a model group The namespaces the replacement elements may be in and how strictly to validate the replacements are determined by the properties, namespace and processContents, of the <<wildcard>> stereotype.



Mapping Rule: Property -> Attribute wildcard

UML Element XSD Element Comments
Property with a stereotypes <<attribute>> and <<wildcard>> or keywords, attribute and wildcard. Attribute wildcard in the enclosing complex type or an attribute group The namespaces the replacement attributes may be in and how strictly to validate the replacement attributes are determined by the properties, namespace and processContents, of the <<wildcard>> stereotype.



Modeling XML schema in UML: Good practices

The purpose modeling XML schema in UML is to create a visual representation of a XML schema and then generate the schema using a UML to XSD transformation. Typically your model will have elements that represent XSD elements as well as elements that are not related XSD. We recommend that you keep the following guidelines in mind when you build such a model.

  1. Put XSD-related elements and non-XSD elements in separate packages.
  2. Put the XSD-related elements belonging to different target namespace in different packages.
  3. Apply the XSD profile to the packages containing XSD related elements. Alternatively, you can also apply the XSD Profile to the model itself.
  4. Apply the <<schema>> stereotype from the XSD profile to each package that contains the XSD-related elements.
  5. Specify the target namespace and its prefix by setting appropriate values to the properties, targetNamespace and targetNamespacePrefix, of the <<schema>> stereotype.
  6. Use the transformation properties to control the contents of the set of packages and classes the UML to XSD transformation needs to process.

Table of Contents

Limitations

This transformation has not yet implemented the rules to generate the following XSD elements:

Table of Contents

Appendix A. Meaning of facets

Facets Meaning
fractionDigits the number of fractional digits must be less than or equal to x
length the length of value must be x
maxExclusive value must be less than x
maxInclusive value must be less than or equal to x
maxLength the length of the value must be less less than or equal to x
minExclusive value must be greater than x
minInclusive value must be greater than or equal to x
minLength the length of the value must be greater than or equal to x
pattern x is one of the regular expressions that the value may match
totalDigits the number of significant digits must be less than or equal to x
whitespace the schema processor should either preserve, replace, or collapse whitespace depending on x

Table of Contents

Appendix B: Simple types and applicable facets

The following table enumerates the built-in data types and the applicable facets. Note that even though W3C recommendation specifies enumeration as a facet, we have not included enumeration in the table. We represent enumeration using a class with the stereotype, <<enumeration>> or using UML enumeration.

Data Types (Restriction Base) Applicable Facets
ENTITY, ID, IDREF length, maxlength, minlength
whitespace is fixed to a value of collapse
pattern is [\i-[:]][\c-[:]]*
IDREFS length, maxlength, pattern
minlength is 1
whitespace is fixed to a value of collapse
Name length, maxlength, minlength
whitespace is collapse
pattern is \i\c*
NCName length, maxlength, minlength
whitespace is collapse
pattern is [\i-[:]][\c-[:]]*
NMTOKEN length, maxlength, minlength
whitespace is fixed to a value of collapse
pattern is \c+
NMTOKENS length, maxlength
minlength is 1
whitespace is fixed to a value of collapse
NOTATION length, maxlength, minlength, pattern
whitespace is fixed to a value of collapse
QNAME length, maxlength, minlength, pattern
whitespace is fixed to a value of collapse
anyURI, base64Binary, hexBinary length, maxlength, minlength, pattern
whitespace is fixed to a value of collapse
language length, maxlength, minlength
whitespace is collapse
pattern is ([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]{1,8})(-[a-zA-Z]{1,8})*
float, double maxExclusive, maxInclusive, minExclusive, minExclusive, pattern
whitespace is fixed to have a value collapse
decimal maxExclusive, maxInclusive, minExclusive, minExclusive, fractionDigits, totalDigits, pattern
whitespace is fixed to have a value collapse
integer data types (integer, byte, int, long, negativeInteger, nonNegativeInteger, nonPositiveInteger, positiveInteger, unsignedByte, unsignedInt, unsignedLong,unsignedShort)

maxExclusive, maxInclusive, minExclusive, minExclusive, totalDigits, pattern
fractionDigits is fixed to have a value 0
whitespace is fixed to have a value collapse
Date and time data types (date, time, dateTime, gYear,gYearMonth, gMonth, gMonthDay, gDay, duration)
maxExclusive, maxInclusive, minExclusive, minExclusive, pattern
whitespace is fixed to have a value collapse
string, normalizedString, token length, maxLength, minLength, pattern
whitespace is preserve for string, replace for normalizedString, and collapse for token


Table of Contents