2

I have some very complex XSD schemas to work with. By complex I mean that each of these XSD would correspont to about 20 classes / tables in a database, with each table having approximately 40 fields. And I have 18 different XSD like that to program.

What I'm trying to achieve is: Get a XML file defined by the XSD and save all the data in a PostgreSQL database using SQLAlchemy. Basically I need a CRUD application that will persist a XML file in the database following the model of the XSD schema, and also be able to retrieve an object from the database and create a XML file.

I want to avoid having to manually create the python classes, the sqlalchemy table definitions, the CRUD code. This would be a monumental job, subject to a lot of small mistakes, given the complexity of the XSD files.

I can generate python classes from XSD in many ways like GenerateDS, PyXB, etc... I need to save those objects in the database. I'm open to any suggestions, even if the suggestion is conceptually different that what I'm describing.

Thank you very much

4

2 回答 2

6

您可以使用 generateDS 从您的 XSD 创建 django 模型。您可以使用 gends_run_gen_django 脚本执行此操作,该脚本位于 generateDS 源代码中的 django 目录下。这是有关该功能的一些文档。相关报价:

以下是该过程的概述:

Step 1. Generate bindings -- Run generateDS.py.
Step 2. Extract simpleType definitions from schema -- Run
gends_extract_simple_types.py.
Step 3. Generate models.py and forms.py -- Run gends_generate_django.py.

脚本 gens_run_gen_django.py 执行这三个步骤。

我相信 django 应该为您提供 sqlalchemy 的大部分功能。但是,如果您决定改用 sqlalchemy,那么 generateDS 的 django 功能可能是一个很好的模型,可以作为类似 sqlalchemy 解决方案的基础。

于 2013-07-19T17:08:43.723 回答
1

不确定是否有直接的方法,但您可以间接从 XSD 转到 SQL Server 数据库,然后从 SQLAlchemy 导入数据库

于 2016-01-12T03:01:06.770 回答