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.
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 Transformations/Configurations list, select UML to XSD. On the Transformation Description page, click View Transformation Documentation.
. From theThe 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:
|
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 |
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.
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.
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.