SDMetrics home page
The Software Design Metrics tool for the UML
Sitemap

Parsing Canonical XMI with SDMetrics

October 28, 2018, Jürgen Wüst. Category: Announcements

I have just released an updated set of project files for UML and SysML. The update resolves a problem when parsing XMI files that conform to the rules of Canonical XMI.

Canonical XMI

The XML document production rules of the XMI 2.x standards leave tool developers quite a few options how an object model can be serialized to XML. There are various ways to identify objects, represent object ownership, encode object properties, determine the order of elements, and so forth.

If you run one and the same UML model through several different XMI exporter implementations, the resulting XMI files are likely to be very different, despite them representing the exact same UML model. Yet, a good XMI importer should be able to deal with all these variations and reconstruct the original model from any of those XMI files.

Canonical XMI (see Appendix B of the XMI 2.5 specification) restricts the choices of the XML production rules, and defines a precise order in which elements and properties must be serialized. Thus, the output files of different Canonical XMI exporter implementations exporting the same model should have identical XML element structures and only differ in minor ways such as the chosen XMI UUIDs. If you can restrict yourself to Canonical XMI, XMI import then becomes a much simpler task.

Source of the problem

SDMetrics’ problem with Canonical XMI concerns the serialization of properties that hold a simple data value (primitive type or enumeration). Consider, for example, properties “name” and “visibility” of operations. Practically every existing XMI 2.x exporter uses XML attributes to serialize such properties, like so:

<uml:Operation xmi:id="op1" xmi:type="uml:Operation" xmi:uuid="DCE:1234" 
               name="op1" visibility="public" />

This is also how SDMetrics expects such properties to be serialized. But the full XMI specification allows for an alternative serialization, using nested XML elements:

<uml:Operation xmi:id="op1" xmi:uuid="DCE:1234" xmi:type="uml:Operation">
  <name>op1</name>
  <visibility>public</visibility>
</uml:Operation>

In Canonical XMI, only this latter option is admissible. Using XML attributes for simple data properties is no longer allowed. This choice seems a bit curious, since it runs against one of the overall goals of XMI 2 to produce smaller and better human readable files. The rationale behind this decision probably involves the consideration of multi-valued data properties. Nested XML elements are better suited to serialize multi-valued data properties, because you can have an arbitrary number of nested XML elements with the same tag name, but you cannot have two or more XML attributes with the same name.

SDMetrics’ XMI import currently does not support the second option with nested XML elements. Hence, if you parse a file that uses nested XML elements for simple data properties, SDMetrics will not pick up the property values.

Solution

Fortunately, this problem is easy to fix. We just need to modify the XMI transformation file to also read the property values from nested XML elements:

<xmitransformation modelelement="operation" xmipattern="uml:Operation" recurse="true">
<trigger name="name" type="attrval" attr="name" />
<trigger name="name" type="ctext" src="name" />
<trigger name="visibility" type="attrval" attr="visibility" />
<trigger name="visibility" type="ctext" src="visibility" />
...
</xmitransformation>

In the download section, you will find updated project file sets for the UML and SysML that contain all the necessary modifications, and instructions how to add them to your SDMetrics installation.

Parsing the XMI Extensions of Enterprise Architect

January 2, 2018, Jürgen Wüst. Category: Announcements,Tips & Tricks

SDMetrics 2.35 introduces a small extension to the XMI parser. Assume we need to access information such as the author or a documentation string from the XMI extension part of Enterprise Architect. This information is encoded as follows: <uml:Model xmi:type=”uml:Model” name=”EA_Model” visibility=”public”> <packagedElement xmi:type=”uml:Package” xmi:id=”4A3564″ name=”test” visibility=”public” /> </uml:Model> <xmi:Extension extender=”Enterprise Architect” extenderID=”6.5″> <elements> <element… [Continue reading]

Generating UML Reports From XMI Files

February 24, 2014, Jürgen Wüst. Category: Development

Occasionally I receive requests from people looking for a simple way to generate a report from an XMI file. For example, they may need to collect a list of all class attributes that satisfy a certain condition, and write them to some HTML or XML file. Depending on the task at hand, XSLT could work… [Continue reading]

Counting OCL Expressions in UML Classes

January 9, 2014, Jürgen Wüst. Category: Tips & Tricks

In this post we’ll look at another real-life case study of how to adapt SDMetrics in order to solve a particular measurement problem. An SDMetrics user needed to count the OCL expressions in classes. SDMetrics does not produce this count out of the box, but needs a little tweaking. In the UML2, an OCL expression… [Continue reading]

Overview of the Changes in SDMetrics V2.31

July 3, 2013, Jürgen Wüst. Category: Announcements

SDMetrics V2.31 was released today. This is a maintenance release that addresses some issues with the XMI import. Automatic recognition of XMI 2.4/2.4.1 files Ever since XMI 1.0, the XMI standards mandated a “version” attribute in the root element of the XMI file to indicate the XMI version of the file. It was simple and… [Continue reading]

Survey of UML Quality Modeling Papers: Less Than One Third Contain Empirical Work

May 28, 2013, Jürgen Wüst. Category: Measurement

I found an interesting review paper titled “A Systematic Literature Review on the Quality of UML Models” by Marcela Genero, Ana Fernández-Saez, H. James Nelson, Geert Poels, and Mario Piattini. It was published in the Journal of Database Management 22 (3), 46-70, 2011. You can also find it here. The paper aims to determine the… [Continue reading]

SDMetrics – Not For UML Models Only

April 8, 2013, Jürgen Wüst. Category: Tips & Tricks

SDMetrics advertizes itself as “The Software Design Metrics tool for the UML”. SDMetrics has a flexible XMI parser to import UML models, as XMI is the most common UML model interchange format. But XMI is not limited to UML model interchange. It can be used to serialize any MOF-based models to XML. Therefore, SDMetrics too… [Continue reading]

Customizing the XMI Import for Enterprise Architect UML Component Diagrams

February 20, 2013, Jürgen Wüst. Category: Tips & Tricks

Recently, some SDMetrics Open Core users approached me with a neat little measurement problem that is ideally suited for this blog. They used Enterprise Architect to create UML 1.3 component diagrams with classifier roles. The XMI output of Enterprise Architect for these diagrams contained several tagged values for the classifier role instances, including two with… [Continue reading]

The Effects of Stability on UML Model Composition Effort

January 23, 2013, Jürgen Wüst. Category: Measurement

The January 2013 issue of “Software & Systems Modeling” contains a new empirical study on UML quality modeling. The paper is titled “Effects of stability on model composition effort: an exploratory study ” by Kleinner Farias, Alessandro Garcia, and Carlos Lucena. The full paper is available for download. Here is my review. The paper investigates… [Continue reading]

More Quality Metrics for UML Sequence Diagrams

December 21, 2012, Jürgen Wüst. Category: Tips & Tricks

In a previous post, we have defined a basic set of size and complexity metrics for UML sequence diagrams with SDMetrics. Today, we’ll add a few more sequence diagram metrics that are potentially useful to identify design flaws. I will show how to implement these metrics using the SDMetricsML. 1. Number of “self” messages The… [Continue reading]

Older Posts »