serialize a class to XML and back

Schneider js at globe.de
Fri May 31 07:21:39 EDT 2013


On 26.05.2013 22:48, Roy Smith wrote:
> In article <mailman.2197.1369600623.3114.python-list at python.org>,
>   Chris Rebert <clp2 at rebertia.com> wrote:
>
>> On May 23, 2013 3:42 AM, "Schneider" <js at globe.de> 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




More information about the Python-list mailing list