python and XML does approximately what XML::Generator does, but in an easier (simpler) way.

I still prefer SimpleXML or almost even Castor or XMLBeans.

Markup may not be good enough for building RESTful web services, but I’m toying with switching the prototype ShoppingList web service over to python –just for fun. Building (and iterating) through complex hierarchies in python *is* nice. Nicer even than perl.


import markup

items = ( "Cookies", "Milk", "Apples" )  

doc ="xml") 
i = 0 
for item in items:
    i = i + 1
    doc.item(item, id_=i, qty_=1)

print doc


<item id="1" qty="1">Cookies</item>
<item id="2" qty="1">Milk</item>
<item id="3" qty="1">Apples</item>

One thought on “python and XML

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s