Data formats: XML, INI, TOML and pickle · 7 / 15 Exercise Medium

Count XML tags

Objective

Walking the whole tree of an XML document is as simple as iterating over the root element with iter().

Instructions

  • The input is a line with an XML document.
  • Show, sorted alphabetically by tag, how many times each one appears (the root included), with the format tag: n.
Input
<lib><book/><book/><dvd/></lib>
Output
book: 2
dvd: 1
lib: 1

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise