UML-to-XSD transformation

In UML, you can create a visual representation of an Extensible Markup Language (XML) schema and then use the UML-to-XSD transformation to generate a XML Schema Definition (XSD) schema. XSD is a language that you use to constrain XML. An XSD schema describes the structure of an XML file. You first model the structure of an XSD schema by applying a set of UML-to-XSD mapping rules. You then apply the UML-to-XSD transformation to the model to generate an XSD schema, which you can use to validate an XML file.

An XSD schema is useful in the following situations:

What you can convert into elements of an XSD schema

The UML-to-XSD transformation generates an XSD schema by converting certain classes in a package of a source model into elements of the schema. You can model several of XSD elements in UML. The transformation uses a set of mapping rules to determine how to generate XSD elements from their corresponding UML elements.

For more information about the mapping rules, read the UML-to-XSD transformation information that is available at Modeling > Transform > Configure Transformations. From the Transformations/Configurations list, select UML to XSD. On the Transformation Description page, click View Transformation Documentation.

The following table lists how the UML-to-XSD transformation converts UML model elements in XSD elements at a high level.

UML model element XSD schema element
Package Single namespace with a prefix
Class Types and reusable groups:
  • Attribute group, named model group, and substitution group
  • Complex type
  • Global element, attribute
  • Simple type
Enumeration Restriction of an XSD string simple type with enumeration facets that are equal to the UML enumeration literals
Note: This differs from a UML class with the <<enumeration>> stereotype from the XSD profile. A stereotyped UML class provides additional general XSD enumerations.
Properties of a class Attributes of an attribute group

Elements and attributes of a complex type

Elements and attributes of a named model group

Association (Aggregation) Child element of a contained element (complex type)
Generalization Derivation by extension of complex type

How the transformation transforms source model elements into XSD schema elements

The UML-to-XSD transformation uses a set of properties to determine how the transformation generates output from source model elements. You must define the value of properties in a UML-to-XSD transformation configuration. The transformations uses these property values to determine the following information:
  • The target namespace of the generated schema
  • The prefix for the target namespace of the generated schema
  • How to transform nested classes
  • Whether to generate a schema for a package that does not have a stereotype or keyword
    Note: By default, the transformation generates a schema for each source package. You can specify that the transformation does not generate a schema for a package that does not have a stereotype or keyword.

When you apply the transformation to a model, the transformation generates a single schema for each package in the source model. When you apply the transformation to a package, the transformation generates a single schema for the package. The transformation does not generate a schema for a nested package.

Where the transformation generates output

The XSD schema that the UML-to-XSD transformation generates is stored in a directory called schema, in the project that you specify as the target for the transformation output. The file that contains the schema has the same name as the package in the source model. The generated schema has .xsd as its file name extension. The transformation displays the generated schema in the Navigator view.

How to learn about using UML to model the structure of an XML file

To learn more about using UML to model an XSD schema, you can copy set of example models to your workspace from the following location in your install directory: /plugins/com.ibm.xtools.transform.uml2.xsd/examples. Each example model includes a description of the model, guidance on using the model, and an example of the generated XSD schema.

Related tasks
Generating XSD schemas from UML models
Related reference
Installed transformations
Feedback
(C) Copyright IBM Corporation 2004, 2005. All Rights Reserved.