[XML-SIG] XML to Object translation

M.-A. Lemburg mal@lemburg.com
Thu, 23 Nov 2000 13:22:30 +0100


Lars Marius Garshol wrote:
> 
> * test e. mail
> |
> | What is the best way to map XML to objects?
> 
> I had an idea yesterday that is not yet implemented, but which will
> probably become an example in my book and probably also something that
> can be downloaded and used separately.
> 
> The idea is basically that when you have an XML document of a
> particular type (say RSS) you make a mapping file that describes how
> to create an object structure from the file. For RSS this might look
> as shown below.
> 
> <object classname="SiteSummary" >
>   <field name = "title">
>     rss / channel / title
>   </field>
> 
>   <field name = "link">
>     rss / channel / link
>   </field>
> 
>   <field name = "description">
>     rss / channel / description
>   </field>
> 
>   <field name = "items">
>     <list elements = "rss / channel / item">
>       <object classname="Item">
>         <field name = "title"> title </field>
>         <field name = "link"> link </field>
>         <field name = "description"> description </field>
>       </object>
>     </list>
>   </field>
> 
> </object>
> 
> This would build from any RSS file a single root object (with title,
> link and description string attributes) with a list attribute holding
> objects with the title, link and description string attributes.

This sounds really cool :-) I presume though, that the classes
you mention in the transformation must exist somewhere to
be instantiated, right ?

BTW, this scheme looks superior to what we have discussed some
months ago about pickling Python to XML. Even though the above
only describes the unpickling process, I think the idea may
also work the other way around.

In any case, this would go a looong way in helping Python read
XML files into Python objects (rather than DOM trees).

-- 
Marc-Andre Lemburg
______________________________________________________________________
Company:                                        http://www.egenix.com/
Consulting:                                    http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/