<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Comments on article "Of Python and XML"</title>
<link>http://base-art.net/Articles/5/</link>
<description>&lt;p&gt;Obviously I'm not the first to believe in the power of Python to ease XML management. Of course there are DOM and SAX which are meant to provide uniform (whatever language we use) XML APIs. After using these for a little while, I'm now convinced OO features should be more used, especially meta-programming.&lt;/p&gt;
&lt;p&gt;Let's get an example. For a school IT project, I needed to provide an OO (partial) abstraction of a DTD. So I started making a class for each XML item type defined in the DTD. The process was always the same:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;if item A includes a list of B items, there was a need for get/set methods to access the given list&lt;/li&gt;
&lt;li&gt;attributes were dealed as Python class variables     (&lt;cite&gt;__getattr__&lt;/cite&gt;, &lt;cite&gt;__setattr__&lt;/cite&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And so on. Then I realized that, the maintenance process would be painfull it the DTD had to be revised. In fact the OO abstraction becomes fully coupled to the DTD.&lt;/p&gt;
&lt;p&gt;After that I discovered Python &lt;a class="reference" href="http://members.rogers.com/mcfletch/programming/metaclasses.pdf"&gt;MetaClasses&lt;/a&gt;. Python is not the only language to provide meta-programming. But, I find it easier to use than SmallTalk's one for example. So now we can imagine things like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
class ItemA(XMLObject):
    BItems = XMList(ItemB)
    index = XMLAttribute(type = StringType)

A = ItemA(someXMLData)
print list(A.BItems)
print A.index
A.index = 'foo'
&lt;/pre&gt;
&lt;p&gt;This concept comes directly from &lt;a class="reference" href="http://sqlobject.org"&gt;SQLObject&lt;/a&gt; (Thanks Ian for this great thing). Adapting these design concepts to the (XML, Python) couple would be quite great.&lt;/p&gt;
</description>
<language>en</language>
<copyright>The contents of this blog are available for non-commercial use only.</copyright>
<generator>Alinea http://pythonfr.org/alinea/</generator>



</channel>
</rss>
