UML to XMI Export Functionality
Microsoft Visio 2002 Professional
Microsoft Visual Studio .NET Enterprise Architect (Visio for Enterprise Architects)
Summary: Learn how the XMI Export download helps developers to access information from a Visio UML model by exporting it to an XML file. (4 printed pages)
This article describes the UML to XMI export functionality that has been added to the Visio UML Solution. Since the UML Solution in Microsoft® Visio® Professional 2002 and Visio for Enterprise Architects (a component of Microsoft® Visual Studio® .NET Enterprise Architect) does not expose an object model API through which UML model elements can be accessed, the export functionality is provided through a separate DLL. The following user scenario describes how a developer can access and use information from a UML model in another application.
A developer wants to write an application that uses information such as class, attribute, or operation names from a UML model that was created with the Visio Professional UML Solution, available from Visio Professional or Visio for Enterprise Architects.
Since the UML Solution does not expose an object model API through which UML model elements can be accessed, the export functionality is provided in a separate DLL (XMIExport.dll). The developer can invoke the XMI Export component and export most of the information contained in static structure, component, and deployment diagrams in an XML file that is compliant with the XMI standard .
The third party application can then parse the XML file using standard techniques like DOM or SAX to access the desired data from the UML model. The DTD file uml.dtd is needed in order to validate and view the XML file, and can be downloaded from the OMG Web site. The supported UML diagrams are class (static structure) diagram (most elements), component diagram (component element), and deployment diagram (node element).
For example, the following UML class (created on a static structure diagram in Visio) will be exported to the corresponding XMI files shown below (note that only a fragment of the XML file is shown).
|+interestRate() : float
+calculate(inout amount : double) : double
<Foundation.Core.ModelElement.name>AccountService</Foundation.Core.ModelElement.name> <Foundation.Core.ModelElement.visibility xmi.value="public" /> <Foundation.Core.GeneralizableElement.isRoot xmi.value="false" /> <Foundation.Core.GeneralizableElement.isLeaf xmi.value="false" /> <Foundation.Core.GeneralizableElement.isAbstract xmi.value="false" /> <Foundation.Core.Class.isActive xmi.value="false" /> <Foundation.Core.ModelElement.name>interestRate</Foundation.Core.ModelElement.name> <Foundation.Core.ModelElement.visibility xmi.value="private" /> <Foundation.Core.Feature.ownerScope xmi.value="instance" /> <Foundation.Core.ModelElement.name>calculate</Foundation.Core.ModelElement.name> <Foundation.Core.ModelElement.visibility xmi.value="public" /> <Foundation.Core.Feature.ownerScope xmi.value="instance" /> <Foundation.Core.BehavioralFeature.isQuery xmi.value="false" /> <Foundation.Core.Operation.specification /> <Foundation.Core.Operation.isPolymorphic xmi.value="false" /> <Foundation.Core.Operation.concurrency xmi.value="sequential" />
The XMI Export functionality is available only through Visio Automation by invoking the
Run command in the Visio API.
To access the XMI export functionality, use the
Run API of the Visio add-on component. The following two parameters must be supplied to the
|Visio UML Solution recognizes the 400 command as the XMI export function|
|This parameter specifies the file where the XMI output will be written. The file name must be double-quote delimited. No blanks are allowed between the "=" and the file name. The file is created if it does not exist. An existing file will be overwritten.|
For example, in Visual C++, the API returns
if the export succeeds.
VAORC rc = (VAORC)cAddon.Run(BSTR_HELPER_CLASS("/CMD=400 /XMIFILE="C:\\TEST.XML""));
Note The sample code files accompanying the XMIExport.dll in the download demonstrate how to invoke the XMI Export functionality of the Visio UML Solution from a Visio add-on. The add-on is built using Microsoft® Visual C++® in Visual Studio .NET.
To install the XMI export facility, copy the XMIExport.dll file to the Visio DLL folder named <VisioInstallationPath>\DLL.
- Load the sample Visual Studio solution file VisioUmlAddon in Visual Studio .NET and build the solution; the result is a file named VisioUmlAddon.vsl in the Debug folder (created by default in the folder where the VS solution file is).
- Copy the VisioUmlAddOn.vsl file to the folder <VisioInstallationPath>\1033\Solutions\Visio Extras.
- Create a UML static structure diagram and add elements to it. From the Visio menu, select Tools, point to Macros, and then click Visio Extras. A new menu item, XMI export, will appear. Select it and choose a file name from the Save As dialog box. A message is displayed (Export to XMI succeeded) after completion of the export process. Browse to the exported .xmi file.
To open the file in Microsoft® Internet Explorer, place the DTD file uml.dtd into the same folder as the saved .xmi file.