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

Depth of an XML tree

Objective

An XML document is a tree, and trees are processed with recursive functions: the depth of an element is 1 plus the greatest depth of its children.

Instructions

  • The input is a line with an XML document.
  • Show its maximum depth: a document with only the root has depth 1.
Input
<a><b><c/></b><d/></a>
Output
3

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

Start exercise