Search⌘ K

How to Edit XML with ElementTree

Explore how to use Python's ElementTree to edit XML files by adding and modifying tags. Learn to change timestamp values to readable formats using Python's time module, and understand how to search XML with find and findall methods to manage and parse XML data.

We'll cover the following...

Editing XML with ElementTree is also easy. To make things a little more interesting though, we’ll add another appointment block to the XML:

XML
<?xml version="1.0" ?>
<zAppointments reminder="15">
<appointment>
<begin>1181251680</begin>
<uid>040000008200E000</uid>
<alarmTime>1181572063</alarmTime>
<state></state>
<location></location>
<duration>1800</duration>
<subject>Bring pizza home</subject>
</appointment>
<appointment>
<begin>1181253977</begin>
<uid>sdlkjlkadhdakhdfd</uid>
<alarmTime>1181588888</alarmTime>
<state>TX</state>
<location>Dallas</location>
<duration>1800</duration>
<subject>Bring pizza home</subject>
</appointment>
</zAppointments>

Now let’s write some code to change each of the begin tag’s values from seconds since the ...