Exporting model structure from StarUML to XML Schema

StarUML is one of the best free UML modeling tools. It has an inbuilt generator that makes it possible to create documentation or implementation (supports few output formats - like as Microsoft Word, Excel, PowerPoint and Text-based). The main disadvantage is that it is impossible to validate or transform the model non-interactively. Detaching a tool from human interaction is crucial when you would like to establish an automated process like Continuous Integration. Because there is no other possibility I decided to transform StarUML native file format directly.

I prepared a simple model structure as a base for tests. It contains two packages with five classes, with aggregation, extending and enumeration.

The class definition in StartUML file looks a little too verbose but clear enough to transform it using XSLT.

<XPD:OBJ name="OwnedElements[0]" type="UMLClass"
  <XPD:ATTR name="Name" type="string">ClassA</XPD:ATTR>
  <XPD:REF name="Namespace">PiM3uWEZCkOZDyvgvtgf8gAA</XPD:REF>
  <XPD:ATTR name="#Attributes" type="integer">2</XPD:ATTR>
  <XPD:OBJ name="Attributes[0]" type="UMLAttribute"
    <XPD:ATTR name="Name" type="string">stringProperty</XPD:ATTR>
    <XPD:ATTR name="Multiplicity" type="string">1</XPD:ATTR>
    <XPD:ATTR name="TypeExpression" type="string">String</XPD:ATTR>
    <XPD:REF name="Owner">NevBjJAxqk+0cnGYi3+mzwAA</XPD:REF>
  <XPD:OBJ name="Attributes[1]" type="UMLAttribute" 
    <XPD:ATTR name="Name" type="string">bClassProperty</XPD:ATTR>
    <XPD:ATTR name="Multiplicity" type="string">0..*</XPD:ATTR>
    <XPD:ATTR name="TypeExpression" type="string">ClassB</XPD:ATTR>
    <XPD:REF name="Type_">ArGKrlhMK0ObSwA9si5FPQAA</XPD:REF>
    <XPD:REF name="Owner">NevBjJAxqk+0cnGYi3+mzwAA</XPD:REF>

To make transformation easy XSLT version 2.0 has been used. Output format will be XML Schema with a separate file for each model package. The algorithm of transformation is very simple:

  1. iterate through model packages with any class or enumeration
  2. iterate through classes or enumerations in package
    • autonomic class generates complexType
    • extending class generates complexType with extension
    • enumeration generates simpleType with restriction and enumeration
  3. iterate through attributes that generates element in output

Each package transforms to a separate schema document with namespace subdomain derived from package path. Stylesheet has less than 200 lines and from the original model generates two valid XML Schema files (first is imported to second one). Objects transformed from the fragment-package are visualized as below.

The tool currently supports single file StarUML documents (without units). You can get it from my files site.

2 komentarze:

Kevin Wells said...

Martin, the link to the XSL file is stale. Can you update it? Thank you, Kevin Wells kwells@icloud.com

Marcin Stefaniuk said...

Check this link http://files.stefaniuk.info/home/exchange-staruml-model-and-xml-schema/exchange-uml-model-and-xml-schema.zip?attredirects=0&d=1

Post a Comment