ElementTree walk

Walk the DOM tree

Use the ElementTree module in the standard library to read an XML document. See people.xml for a sample XML document.

  1. Parse the document to get a document object.
  2. Get the root node from the document.
  3. Walk the DOM tree.
  4. For each node in the tree, print out (1) the element (tag) name, (2) the attributes of the node (name and value), and (3) text content of the node.

What you will learn:

Modify the tree

  1. Add a date attribute to each "person" element.
  2. Add a new "person" element.
  3. Walk and display the tree, again.

What you will learn:

Additional information