I recently got a request to import a database schema definition into Enterprise Architect from an OData metadata XML file. OData or Open Data Protocol is an OASIS standard with a definition of best practises for building and consuming RESTful APIs. A metadata document is an XML file with the description of the available entities, properties, etc.
In addition to the file to process and import, I reviewed the content from publicly available OData metadata sample files:
- services.odata.org/OData/OData.svc/$metadata : Product entity definition.
- services.odata.org/V4/TripPinServiceRW/$metadata : Airport and trip details.
I couldn't use EA XML Schema (XSD) import since it does not support XML files, even when it defines a data structure (here entities and properties). OData metadata XML files use the EDM schema available here: docs.oasis-open.org/odata/odata-csdl-xml/v4.01/cs01/schemas/edm.xsd.
As I had to manipulate XML data and needed a lightweight, easy-to-use solution, I identified the XML Transformation Language (XSLT) as the appropriate solution.
XSLT makes it possible to convert content from an XML and generate a file with a content matching a number of rules, defined in a template (XSL file). My aim here to create a CSV (comma-separated values) file with a list of UML classes and attributes from the OData metadata file. An enhanced version of Geert Bellekens' free Excel VBImporter would then let me run a bulk import of the resulting entities (classes) and their properties (attributes) into EA.
Process:
- I opened the first OData metadata XML file in Notepad++.
- I used the XML Tools plugin to run the XSL Transformation.
- I selected the XSL file that contains the initial set of rules to convert...
- EnumType elements to Enumeration classes,
- EntityType elements to entityType stereotyped classes,
- ComplexType elements to classes,
- EntityContainer elements to entityContainer stereotyped classes.
- Note: attributes matching the properties are included.
- Notepad++ XSL Transformation function generated a new file with the expected CSV content (note: the XML tag needs to be removed before saving the file)
- I opened the Excel VBImporter to import classes and attributes (note: EA CSV import is limited to elements i.e. Classes).
- I imported the CSV content to populate the VBImporter.
- Finally, having opened EA and a target package, I ran VBImporter Class import.
Note: other tools than Notepad++ can be used to run the XSL Transformation, e.g. Visual Studio, xsltproc in Linux, etc.
I have not yet published the XSL file which contains the relevant rules to use and improve. Please feel free to contact me to get a copy, test it, use it, and improve it!