Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'schema': 0.05; 'classes.': 0.09; 'converted': 0.09; 'impose': 0.09; 'instances.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'cases:': 0.16; 'received:10.50': 0.16; 'subject:XML': 0.16; 'subject:class': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'restrictions': 0.19; 'starts': 0.20; 'gmbh': 0.22; 'cc:addr:python.org': 0.22; 'header:User- Agent:1': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'references': 0.26; 'defined': 0.27; 'header:In-Reply-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; 'text': 0.33; '(e.g.': 0.33; 'maybe': 0.34; 'classes': 0.35; 'instances': 0.36; 'too': 0.37; 'received:10': 0.37; 'easily': 0.37; 'e.g.': 0.38; 'anything': 0.39; 'how': 0.40; 'even': 0.60; 'subject:back': 0.60; 'mentioned': 0.61; 'numbers': 0.61; 'back': 0.62; 'exchange': 0.63; 'different': 0.65; 'containing': 0.69; 'special': 0.74; '260': 0.84 X-Virus-Scanned: Debian amavisd-new at ispconfig-mx01-ha03.globe.de Date: Fri, 31 May 2013 13:16:21 +0200 From: Schneider Organization: GLOBE Development GmbH User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: dieter Subject: Re: serialize a class to XML and back References: <519DF151.1080405@globe.de> <87zjvjppsh.fsf@handshake.de> In-Reply-To: <87zjvjppsh.fsf@handshake.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369999487 news.xs4all.nl 15959 [2001:888:2000:d::a6]:33350 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46597 On 25.05.2013 07:54, dieter wrote: > Schneider 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