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


Groups > comp.lang.python > #45967

Re: serialize a class to XML and back

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'schema': 0.05; 'classes.': 0.09; 'converted': 0.09; 'impose': 0.09; 'instances.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'cases:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:XML': 0.16; 'subject:class': 0.16; 'bit': 0.19; 'restrictions': 0.19; 'starts': 0.20; 'header:User-Agent:1': 0.23; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'xml': 0.29; 'related': 0.29; 'document.': 0.30; '(maybe': 0.31; 'adequate': 0.31; 'writes:': 0.31; 'class': 0.32; '(e.g.': 0.33; 'maybe': 0.34; 'classes': 0.35; 'instances': 0.36; 'charset:us-ascii': 0.36; 'too': 0.37; 'easily': 0.37; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'subject:back': 0.60; 'mentioned': 0.61; 'back': 0.62; 'received:217': 0.63; 'exchange': 0.63; 'different': 0.65; 'special': 0.74
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From dieter <dieter@handshake.de>
Subject Re: serialize a class to XML and back
Date Sat, 25 May 2013 07:54:54 +0200
References <519DF151.1080405@globe.de>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Gmane-NNTP-Posting-Host pd9e0a2f9.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
Cancel-Lock sha1:bGUtQYbXy04pXg0jgX9owY/0EmY=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2112.1369461313.3114.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369461313 news.xs4all.nl 15950 [2001:888:2000:d::a6]:37006
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45967

Show key headers only | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web