Next / Previous / Contents / TCC Help System / NM Tech homepage

9.9. Element.getchildren(): Get element children

For an Element instance E, this method returns a list of all E's element children:

E.getchildren()

Here's an example:

>>> xml = '''<corral><horse n="2"/><cow n="17"/>
...  <cowboy n="2"/></corral>'''
>>> pen = etree.fromstring(xml)
>>> penContents = pen.getchildren()
>>> for  content in penContents:
...     print "%-10s %3s" % (content.tag, content.get("n", "0"))
... 
horse        2
cow         17
cowboy       2
>>>