serialize a class to XML and back
Schneider
js at globe.de
Fri May 31 07:16:21 EDT 2013
On 25.05.2013 07:54, dieter wrote:
> Schneider <js at 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
More information about the Python-list
mailing list