xml file structure for use with ElementTree?

Stewart Midwinter stewart.midwinter at gmail.com
Sat Oct 9 18:07:14 CEST 2004

Andrew Dalke <adalke at mindspring.com> wrote 
> Legal XML would look like
>   <person name="joe" sex="male" age="49"></person>

sigh... after a good night's sleep I discovered that myself this
morning.  It's obvious, of course.

> for person in tree.findall("person"):
>    if person.attrib["name"] == "joe":
>      tree.remove(person)
>      break
> else:
>    raise AssertionError("Where's joe?")

That's the ticket!  Unfortunately at the moment when I run this code I
get the following error:'
ElementTree instance has no attribute 'remove'
but I'll try to work through that.

> Given what you've shown, you need a reference to XML
> and not ElementTree.  The latter assumes you understand
> the former.  I don't have one handy.

that's a polite way of saying I'm clueless about XML, which is true! 
The main appeal of ElementTree was so I could avoid having to learn a
whole lot about XML in order to parse a simple file, but I am coming
to the conclusion that ElementTree is only simple if you already have
an understanding about XML.

thanks again,

More information about the Python-list mailing list