Print this page
Tuesday, 10 July 2018 14:14

Import a database schema from an OData $metadata to Enterprise Architect

Written by
Rate this item
(2 votes)

odata metadata to sparx enterprise architect

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: 

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++.

odata metadata file xml

  • 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.

xslt odata to csv

  • 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)

xslt odata to csv result

  • 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.

vbimporter odata csv to EA

  • Finally, having opened EA and a target package, I ran VBImporter Class import.

odata classes uml in sparx EA

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!