Hi all,
I am attempting to create an XML document dynamically with Python. It
needs the following format:
<zAppointment s reminder="15">
<appointment>
<begin>11797758 00</begin>
<duration>180 0</duration>
</appointment>
</zAppointments>
I tried using minidom with the following code:
<code>
from xml.dom.minidom import Document
doc = Document()
zappt = doc.createEleme nt('zAppointmen ts')
zappt.setAttrib ute('reminder', '15')
doc.appendChild (zappt)
appt = doc.createEleme nt('appointment ')
zappt.appendChi ld(appt)
begin = doc.createEleme nt('begin')
appt.appendChil d(begin)
f = file(r'path\to\ file.xml', 'w')
f.write(doc.top rettyxml(indent =' '))
f.close()
</code>
This gives me the following:
<?xml version="1.0" ?>
<zAppointment s reminder="15">
<appointment>
<begin/>
<duration/>
</appointment>
</zAppointments>
How do I get Python to put values into the elements by tag name? I can
parse my documents just fine, but now I need to edit them and write
them out to a file for an application I am working on. I am sure I am
missing something obvious.
Thanks a lot!
Mike
I am attempting to create an XML document dynamically with Python. It
needs the following format:
<zAppointment s reminder="15">
<appointment>
<begin>11797758 00</begin>
<duration>180 0</duration>
</appointment>
</zAppointments>
I tried using minidom with the following code:
<code>
from xml.dom.minidom import Document
doc = Document()
zappt = doc.createEleme nt('zAppointmen ts')
zappt.setAttrib ute('reminder', '15')
doc.appendChild (zappt)
appt = doc.createEleme nt('appointment ')
zappt.appendChi ld(appt)
begin = doc.createEleme nt('begin')
appt.appendChil d(begin)
f = file(r'path\to\ file.xml', 'w')
f.write(doc.top rettyxml(indent =' '))
f.close()
</code>
This gives me the following:
<?xml version="1.0" ?>
<zAppointment s reminder="15">
<appointment>
<begin/>
<duration/>
</appointment>
</zAppointments>
How do I get Python to put values into the elements by tag name? I can
parse my documents just fine, but now I need to edit them and write
them out to a file for an application I am working on. I am sure I am
missing something obvious.
Thanks a lot!
Mike
Comment