[xsd-users] Re: Can one use ODB with Classes generated by XSD

B Hart bhartsb at gmail.com
Wed May 2 11:44:32 EDT 2012


Hello Boris,

(this is a re-post as the original thread is quite old and may getting
buried).

Per my earlier thread titled "Can one use ODB with Classes generated
by XSD"since
ODB now supports MS SQL and I'm at a place where I might be able to use
ODB, and my requirements have changed .  Particularly I no longer have the
need to map my schema into an existing DB that doesn't match the schema
well.  That is I'm going to create a DB that matches the Schema.

I've used CodeSynthesis XSD to generate classes for a set of schemas that
happen to be nicely hierarchical.  Essentially the XSDs define the elements
for patient care records.  Each record has up to ~550 elements divided into
~23 subsections/categories.  Elements in the subsections have all the
different cardinalities.  For example, elements relating to adminstering a
medication are defined in a complex element with cardinality sequence
(since multiple medications might be administered to the same patient, or
the same medication given at different times).

As an evaluation exercise I generated a DB schema from the XSDs using
Altova's XMLSpy.  It generated a set of tables very reflective of the
organization of the XML Schemas as well as the element constraints.  I'm
wondering if I similarly relied on ODB to generate the tables if it would
produce a similar DB schema, as well as the constraints based on the
element types?  Haven't tried it yet.

Also, I'm wondering if item #2 below has been implemented?  I have written
a program that with excellent help from XSD generated classes reads in
patient records in an XML file, validates the XML, and checks various
business rules and generates a report.  At the point after validation has
occurred and Business Rules are checked and pass, the data is ready to put
into the DB.  It would be nice if I could use ODB to generate the Schema
and make it happen with just a few lines of code (similar to how easy it is
with XSD to read in a complex schema and serialize it out again.).

Thanks in advance for your comments.

Boris Kolpackov:

I see two possible approaches here, depending on how closely the
XML vocabulary models the database representation.

1. If XML and database models are very different (as in the case you
  described above), then the best approach would probably be to have two
  object models (sets of C++ classes): the first is for XML (generated
  by the XSD compiler) and the second is for the database (hand-written
  or auto-generated by ODB SQL-to-C++ compiler from the existing schema,
  something that is on our TODO list). Once you have the two models, you
  manually write the code that convert between the two, such as
  performing merging and splitting of members, etc.

2. If XML models the database pretty closely, then you can take the
  XSD-generated model and map it (using ODB pragmas) to the database
  tables (those can be placed into a separate file and included into
  the ODB compilation with the --odb-epilogue option). Once that is
  done, you can just load the classes from XML and store them into
  the RDBMS.


More information about the xsd-users mailing list