Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45967 > unrolled thread

Re: serialize a class to XML and back

Started bydieter <dieter@handshake.de>
First post2013-05-25 07:54 +0200
Last post2013-05-25 07:54 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: serialize a class to XML and back dieter <dieter@handshake.de> - 2013-05-25 07:54 +0200

#45967 — Re: serialize a class to XML and back

Fromdieter <dieter@handshake.de>
Date2013-05-25 07:54 +0200
SubjectRe: serialize a class to XML and back
Message-ID<mailman.2112.1369461313.3114.python-list@python.org>
Schneider <js@globe.de> writes:

> how can I serialize a python class to XML? Plus a way to get the class
> back from the XML?
>
> My aim is to store instances of this class in a database.

In case you want to describe the XML data via an XML-schema
(e.g. to exchange it with other applications; maybe via
WebServices), you may have a look at "PyXB".


The approach of "PyXB" may be a bit different from yours:

  It starts with an XML-schema description and from
  it generates Python classes corresponding to the types
  mentioned in the schema.

  Instances of those classes can then be easily serialized
  to XML and XML documents corresponding to types defined
  in the schema can easily be converted into corresponding
  class instances.

  It is not too difficult to customize the classes
  used for a given type - e.g. to give them special methods
  related to your application.


You may want to start with your (arbitrary) Python classes
and get their instances serialized into an adequate XML document.

This will not work in all cases: some things are very difficult
to serialize (maybe even not serializable at all - e.g. locks).

If you plan to use anything already existing, then almost
surely, this will impose restrictions of your classes.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web