title: Display XML tree structure with BeautifulSoup
body: <p>When working with a new XML structure, it is always helpful to see the big picture first.</p>
  
  <p>When loading it with <code>BeautifulSoup</code>:</p>
  
  <pre><code>import requests, bs4
  s = requests.get('https://www.w3schools.com/xml/cd_catalog.xml').text
  x = bs4.BeautifulSoup(s, 'xml')
  print(x)
  </code></pre>
  
  <p><strong>is there a built-in way to display its tree structure with different depths?</strong></p>
  
  <hr>
  
  <p>Example for <a href="https://www.w3schools.com/xml/cd_catalog.xml" rel="nofollow noreferrer">https://www.w3schools.com/xml/cd_catalog.xml</a>, with <code>maxdepth=0</code>, it would be:</p>
  
  <pre><code>CATALOG
  </code></pre>
  
  <p>with <code>maxdepth=1</code>, it would be:</p>
  
  <pre><code>CATALOG
    CD 
    CD
    CD
    ...
  </code></pre>
  
  <p>and with <code>maxdepth=2</code>, it would be:</p>
  
  <pre><code>CATALOG
    CD 
      TITLE
      ARTIST
      COUNTRY
      COMPANY
      PRICE
      YEAR
    CD 
      TITLE
      ARTIST
      COUNTRY
      COMPANY
      PRICE
      YEAR
    ...
  </code></pre>