Python <--> XML data binding.

Harry George hgg9140 at seanet.com
Tue Jun 6 17:58:00 EDT 2000


I've also been writing a package along these lines.  Start with a
neutral representation (phase 1 used UML, phase 2 uses a python list
format, phase 3 will code directly from python class defs).  Generate

a) SQL data def and data manipulation code
b) UML XMI xml file
c) DTD and xml reader/writer


The truth is, I haven't done much on this recently, because
hand-coding xml reader/writers is utterly trivial once you have some
design patterns.  I generally structure the job as:

1 module per xml dtd.  In some cases this has resulted in 1000 LOC
modules, but each class in the file is self contained so maintenance
is no hassle.

The root object is XYZ_File, representing the xml file itself (e.g.,
file name, version).  Also has file-level tree decorations (e.g.,
cross references).

The various domain-specific classes are written in a neutral format,
with a "from_dom" and a "to_dom" method to handle translation.  Do a
bit of processing to get things in and out of raw XML formatting, but
retain the local semantics.

A good deal of the coding after that is transforming one OO rep
to another -- i.e., the semantics of moving from one domain to
another.  The xml just shows up in the input and output stages.  E.g.:

domain1.xml-->domain1.py-->domain1_to_domain2.py-->domain2.py-->domain2.xml

I'm finding that the best approach is to build the python OO
representations first, and then figure out how to serialize them to
xml.  DTD's are useful for inter-community transfer, but hardly
appropriate for data modeling. 

Paul Prescod <paul at prescod.net> writes:

> Werner Fouche wrote:
> > 
> > Does anyone know if a tool exist that will generate Python data binding code
> > for an XML DTD similar to what Breeze ( http://www.breezefactor.com ) does
> > for Java.
> 
> I'm working on such a library. Check back in a couple of weeks.
> 
> Nevertheless, the Breeze website vastly exaggerates the difficulty of
> doing object creation "by hand" using the output of a parser. I wouldn't
> even bother with my data binding technology if the data binding did not
> come "for free" as a side effect of other features I need.
> -- 
>  Paul Prescod
> Those who profess to favor freedom and yet depreciate agitation, are men
> who want crops without plowing up the ground. They want rain without
> thunder and lightning. They want the ocean without the roar of its many
> waters. - Fredrick Douglass
>  http://www.informamerica.com/Articles/Quotes.htm
> 

-- 
Harry George
hgg9140 at seanet.com



More information about the Python-list mailing list