UML-to-XSD transformations
XSD files
An XSD file is an instance of an XML schema that is written in the XML Schema language. An XSD file, or schema, describes the structure of an XML file. It also defines the elements and attributes that can be included in an XML schema, the relationships between the elements and attributes, as well as the constraints on the elements and attributes. You first model the structure of an XML 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 file, which you can use to validate an XML file.
- To validate data by checking for items such as required tags
- To generate a description of the structure of an XML file that you can use as a data content standard between teams
- To generate system documentation by annotating the schema to provide additional information
- To specify default values that an application can use if a given XML file does not specify all the values that an application requires
- To identify the information that is specific to a given application and that the application uses to process an XML document
Guidelines for modeling an XML schema in UML
You can use UML to create a visual representation of an XML schema, and then you can run the UML-to-XSD transformation to generate an XSD file. A model can contain elements that represent XSD elements, as well as elements that are not related to XSD.
Use the following guidelines when you create UML models that represent XML schemas:
- Put XSD-related elements and non-XSD elements in separate packages.
- If XSD-related elements belong to different target namespaces, put the elements in different packages.
- Apply the XSD Transformation profile to the packages that contain XSD-related elements. Alternatively, you can apply the XSD transformation profile to the model. If you create a new model project using one of the templates in the XSD Transformation Profile category, the XSD Transformation profile is automatically applied to the model.
- Apply the «schema» stereotype in the XSD transformation profile to each package that contains XSD-related elements.
- Specify the target namespace and namespace prefix by the targetNamespace and targetNamespacePrefix properties of the «schema» stereotype, if needed.
- Specify appropriate values in the transformation configuration to determine how the transformation transforms UML packages and classes.
How the transformation transforms UML elements into XSD schema elements
- The target namespace of the generated schema
- The prefix for the target namespace of the generated schema
- Whether to overwrite transformation output files without warning
- How to transform nested classes
- Whether to transform a class that does not have a stereotype or keyword
- Whether to generate a schema for a package that does not have a stereotype or keyword
- Whether to generate all the XSD files in "schema" folder or in a folder that follows the package name
- Whether to generate all classes in the same package in one XSD file or each class in different XSD file
By default, the transformation generates a schema for each package and its contents that you select in the source model. You can specify whether the UML-to-XSD transformation generates a schema for packages that do not have the «schema» stereotype or schema keyword. The transformation does not generate a schema for a nested package.
By default, the transformation processes all classes contained in the packages that you select as the source of the transformation. You can specify whether the UML-to-XSD transformation processes classes that do not have a stereotype or keyword.
Valid sources for the UML-to-XSD transformation
The UML-to-XSD transformation generates XSD files from the following UML sources:- UML models containing at least one package
- UML packages
Valid targets for the UML-to-XSD transformation
You can specify any project or folder in your workspace as the target for the output of the UML-to-XSD transformation.
Location of transformation output
The location of the UML-to-XSD transformation output depends on the value set for the Target folder property. The additional options enable the output to be created in a package name or names of your choice and enable the creation of separate files for each data type to support IBM® WebSphere® Integration Developer projects.
UML elements that transform into elements of an XSD schema
You can model several XSD elements in UML. The transformation uses a set of mapping rules to determine how to generate XSD elements from their corresponding UML elements.The following table lists how the UML-to-XSD transformation transforms UML model elements in XSD elements.
| UML model element | XSD schema element |
|---|---|
| Package | Single namespace with a prefix |
| Class | Types and reusable groups:
|
| DataType | Types and reusable groups:
|
| Signal | Types and reusable groups:
|
| Association class | Consider a model that contains two UML classes and one association
class between them. By default, the transformation generates one XSD
file that contains a complex type for each UML class and the association
class. In the transformation configuration editor, on the Output Options page, if you select the Create a separate file for each data type check box, when you run the transformation it generates an XSD file for each UML class and the association class. Each file contains a corresponding complex type and the required import statements. After you run the UML-to-XSD transformation, your might run a UML-to-WSDL transformation that references the same UML classes as those specified as the source of the UML-to-XSD transformation. For information about how the UML-to-WSDL transformation generates WSDL elements in this scenario, see the link to the related reference topic at the end of this topic. |
| 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 UML-to-XSD
transformation 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 |
| Property with attribute stereotype | Attribute of the complex type, if the property is a simple type and has a multiplicity of [0..1]; otherwise, converted into an element |
| Association (Aggregation) | Child element of a contained element (complex type) |
| Generalization | Derivation by extension of complex type |
Integration with team support
The transformation provides integration functionality with IBM Rational® Team Concert™, CVS, Rational ClearCase®, and Rational ClearCase LT version control systems, which enables you to automatically check out files or add new files. You must enable team capabilities to work with configuration management systems.