Convert DB table to XML - a worked example

If you have a database table which you wish to convert into a Zymonic XML defined table, this can be a laborious task. Luckily 2 toolkit commands (import_from_db) and (export_def) can be used to automatically generate a Zymonic XML definition to replicate any DB table, below is an example.

=The situation=

We have a 'legacy' database table that we wish to use in Zymonic.

=Importing=

First we run the import_from_db command below:



It's worth noting that here you must put the database that currently has the table, the system you wish to add the xml to, and the sql/db name of the table.

This has added the system definition to the export_test's db, in the table zz_system_definition. We can then do a config build, and the definition will be added from this table, to the system. After, when we run export_def:



There is now a system definition in export_test, of the table (with the definitions of the fields seperately outside of the table, but inside the Zymonic tags, if you are worried about these znames being duplicates of current existing ones, there are params to pass in field and table zname prefixes).

=Editing=

Once the definition has been config built into the system, the definition of the table can be viewed and edited from the system GUI with 'User System Definitions List' (although I won't here because I want to test that the tables come out identical):



=Exporting=

Now producing a bit of user-style xml is as simple as redirecting the output of export_def to a file:



This can then be added to your system in /etc/zymonic/system, and when a config build is run the table (and process and filter if you had the flags set to autocreate them), will be added to the system. (Before config building, you may need to delete from zz_system_definition and remove the perist file "sudo rm /etc/zymonic/export_test/ZZPersist.conf" before config building if you get zname conflicts.)

Below is a comparison of the explains of the original table, and the table produced (with the fields re-ordered for clarity):