On May 22, 7:30 pm, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I am attempting to create an XML document dynamically with Python. It
> > needs the following format:
>
> > <zAppointments reminder="15">
> >    <appointment>
> >            <begin>1179775800</begin>
> >            <duration>1800</duration>
> >         </appointment>
> > </zAppointments>
>
> Try lxml.objectify.
>
> http://codespeak.net/lxml/dev/objectify.html
>
>   >>> from lxml import etree, objectify
>   >>> zAppointments = objectify.Element("zAppointments")
>   >>> zAppointments.set("reminder", "15")
>   >>> zAppointments.appointment = objectify.Element("appointment")
>   >>> zAppointments.appointment.begin = 1179775800
>   >>> zAppointments.appointment.duration = 1800
>
>   >>> print etree.tostring(zAppointments, pretty_print=True)
>   <zAppointments reminder="15">
>     <appointment>
>       <begin>1179775800</begin>
>       <duration>1800</duration>
>     </appointment>
>   </zAppointments>
>
> Pretty much what one would expect.
>
> Stefan

Stefan,

This looks really cool. I'll try implementing it sometime today and
see if it affects my execution time any. It's definitely clearer
code...at least in my opinion.

Mike

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to