Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any opensource tool for converting xml schema to database schema for linux?

Is there any opensource tool which convert xml schema to database schema for linux. All I need is it should read xml schema, generate corresponding database schema and create tables with that. I tried to google and all I could find is xsd2db and its written in c#, but of no use for me. I am using centos and my database is postgresql. Any help is appreciated. Thanks in advance.

like image 652
aMa Avatar asked Feb 16 '12 14:02

aMa


1 Answers

Native support appears on the way, but I can't find anything native. Also not finding any kind of decent tools to do the job.

So, I though this would be a neat weekend project to learn a bit more about XSD. I created xsd2pgsql to handle this. It's still pretty rough around the edges, so I'd like you to try it out and let me know of any problems you have. Or fork it if you'd like to help.

XML isn't the greatest format to represent a database since it's 3d and a DB is pretty much 2d. So some assumptions are made by this script, like all element children of root are the primary table and any complexType after that will be a table. That said, this should work on most XML Schemas(or at least the few I've tested).

You can get all the options with the -h option. But basically, you can provide it with the XSD file(s) as the arguments and you can use the options to change behavior slightly or to have it run the SQL directly on your DB. If it's a production system, I'd recommend not connecting directly to the DB and making sure the SQL output is good to go or not, and to make any adjustments.

Here's an example usage with the sample files in the repository: python xsd2pgsql.py -f sample-2.xsd sample.xsd

NOTE: Currently this doesn't handle any relations/references between tables/XML complex types. You'll have to add those and any indexes you want after the fact. Custom namespaces aren't yet supported either.

Hope this helps.

like image 92
Mike Shultz Avatar answered Oct 03 '22 00:10

Mike Shultz