Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'languages,': 0.04; 'third- party': 0.04; '(python': 0.07; 'context': 0.07; 'json': 0.07; 'latter': 0.09; 'newest': 0.09; 'objects)': 0.09; 'solution,': 0.09; 'python': 0.11; '23,': 0.16; 'apis.': 0.16; "can't.": 0.16; 'data)': 0.16; 'develop.': 0.16; 'json,': 0.16; 'received:10.50': 0.16; 'roy': 0.16; 'subject:XML': 0.16; 'subject:class': 0.16; 'wrote:': 0.18; 'module': 0.19; '>>>': 0.22; '(in': 0.22; 'gmbh': 0.22; 'header:User-Agent:1': 0.23; 'certainly': 0.24; 'convenient': 0.24; 'entries': 0.24; 'instead.': 0.24; 'question': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'xml': 0.29; 'compared': 0.30; "i'm": 0.30; 'pickle': 0.31; 'releases,': 0.31; 'class': 0.32; 'problem': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'instances': 0.36; 'library.': 0.36; 'url:org': 0.36; 'received:10': 0.37; 'performance': 0.37; 'feed': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'subject:back': 0.60; 'back': 0.62; "you'll": 0.62; 'more': 0.64; 'side': 0.67; 'smith': 0.68; 'article': 0.77; '260': 0.84; 'faster.': 0.84; 'rebert': 0.84; '2013': 0.98 X-Virus-Scanned: Debian amavisd-new at ispconfig-mx01-ha03.globe.de Date: Fri, 31 May 2013 13:21:39 +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: python-list@python.org Subject: Re: serialize a class to XML and back References: <519DF151.1080405@globe.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369999368 news.xs4all.nl 15958 [2001:888:2000:d::a6]:60300 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46596 On 26.05.2013 22:48, Roy Smith wrote: > In article , > Chris Rebert wrote: > >> On May 23, 2013 3:42 AM, "Schneider" wrote: >>> Hi list, >>> >>> how can I serialize a python class to XML? Plus a way to get the class >> back from the XML? >> >> There's pyxser: http://pythonhosted.org/pyxser/ >> >>> My aim is to store instances of this class in a database. >> Honestly, I would avoid XML if you can. Consider using JSON (Python >> includes the `json` module in the std lib) or pickle instead. Compared to >> XML: The former is more standardized (in the context of serializing >> objects) and less verbose; the latter is more efficient (if you don't care >> about cross-language accessibility); both have more convenient APIs. > Some other points... > > If you care about efficiency and want to use json, don't use the one > that comes packaged with the standard library. There are lots of > third-party json packages (ujson is the one we use) which are > significantly faster. Not sure if that's true of the newest python > releases, but it was certainly true in 2.6. I think performance can be a problem in future. This question is part of a multi-user rss-reader solution, which I'm going to develop. I want to store the feed entries (+ some additional data) as XML in a database. > The advantage of pickle over json is that pickle can serialize many > types of objects that json can't. The other side of the coin is that > pickle is python-specific, so if you think you'll ever need to read your > data from other languages, pickle is right out. -- GLOBE Development GmbH Königsberger Strasse 260 48157 MünsterGLOBE Development GmbH Königsberger Strasse 260 48157 Münster 0251/5205 390