Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46597
| Date | 2013-05-31 13:16 +0200 |
|---|---|
| From | Schneider <js@globe.de> |
| Organization | GLOBE Development GmbH |
| Subject | Re: serialize a class to XML and back |
| References | <519DF151.1080405@globe.de> <87zjvjppsh.fsf@handshake.de> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2489.1369999487.3114.python-list@python.org> (permalink) |
On 25.05.2013 07:54, dieter wrote: > 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). I have just small classes containing text (strings) numbers (as ids) and references to other classes of this type. > > If you plan to use anything already existing, then almost > surely, this will impose restrictions of your classes. > -- GLOBE Development GmbH Königsberger Strasse 260 48157 MünsterGLOBE Development GmbH Königsberger Strasse 260 48157 Münster 0251/5205 390
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: serialize a class to XML and back Schneider <js@globe.de> - 2013-05-31 13:16 +0200
csiph-web