There are a couple of different methods one can employ for capturing the XML model data and putting it into a data store, including, as you might expect, using XSLT. But I'm going to take a different approach, using the C# language. XSLT is a good choice for changing XML files but for more extensive applications that do more than transform data, C# or another high-level language like Java offer more flexibility.
In this article I will take the same ideas and samples from my earlier XMI article, and show how a UML deployment diagram can be dissected using XMI and C#. I'll begin with a simple deployment diagram of the servers within a fictional car leasing company and use C# to capture some data. This data can easily be added to a database (it is a relatively easy set of ADO calls) or as part of a larger asset based management system. With each example, I'll add complexity to the original diagram and the information being grabbed.
Example 1: Looking for Server Names
Note: In the last article I mentioned that Enterprise Architect stored each diagram as a separate XMI file but in fact it is by the project.
I will first develop a simple main program that prompts for the name of an XML document representing a valid XMI document. Once the file name is entered it is passed to an object that parses the XMI document and prints out the server names.
using System;
using System.Text;
namespace XMI_1
{
public class ConsoleUtils
{
public static string ReadString(string msg)
{
Console.Write(msg);
return System.Console.ReadLine();
}
public static void WriteString(string msg)
{
System.Console.WriteLine(msg);
}
public static void Main(string[] args)
{
string name = ReadString("Please enter the XMI filename : ");
NodeParse np = new NodeParse(name);
System.Console.ReadLine();
}
}
}
Please enable Javascript in your browser, before you post the comment! Now Javascript is disabled.
Your name/nickname
Your email
WebSite
Subject
(Maximum characters: 1200). You have 1200 characters left.