[ZODB-Dev] Export and Import

Magnus Lyckå magnus@thinkware.se
Wed, 27 Feb 2002 01:08:29 +0100


I'm developing a non-ZOPE application with ZODB as
my database. I was thinking about exporting my data
in some kind of text format. XML seems suitable.

Does anyone have experiences or code to share here.
I'd like to reinvent as few wheels as possible...

There are a lot of joins between objects in my code.
In some cases there are pure tree structures and I
thought I'd let them be represented as a corresponding
tree structure in the XML. In other cases we have more
comples DAG structures, and in those cases i just
thought I'd list all involved objects and store OIDs
representing the relations in the relevant places.

It doesn't seem like a big thing to make all classes
capable of representing their instances as XML, and
to traverse through all the objects. Although if anyone
has suggestion on tools to use etc, I'm greatful.

What seems more tricky at this stage is to get the
objects back into ZODB again. For instance, I guess
I have to change all my __init__ functions, so that
they can create objects from XML. I'm not sure how
easy that is...

It also seems to me that I have to first create
all my objects, and then traverse through the
objects to replace the OID from the XML with a
real pointer between the objects. Although I
suppose I can use a lazy approach here, and just
store the OID untill someone wants to traverse the
relationship...

It also seems to me that reading an XML file
and creating objects from that is more work than
the opposite, and that mystical things like DOM
could be useful. (I'm sure DOM won't be so mystical
once I start use it...)

Suggestions anyone?


-- 
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se