title: How to get BeautifulSoup 4 to respect a self-closing tag?
body: <p>This question is specific to <a href="http://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="noreferrer">BeautifulSoup4</a>, which makes it different from the previous questions:</p>
  
  <p><a href="https://stackoverflow.com/questions/1567402/why-is-beautifulsoup-modifying-my-self-closing-elements">Why is BeautifulSoup modifying my self-closing elements?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2211589/selfclosingtags-in-beautifulsoup">selfClosingTags in BeautifulSoup</a></p>
  
  <p>Since <code>BeautifulStoneSoup</code> is gone (the previous xml parser), how can I get <code>bs4</code> to respect a new self-closing tag? For example: </p>
  
  <pre><code>import bs4   
  S = '''&lt;foo&gt; &lt;bar a="3"/&gt; &lt;/foo&gt;'''
  soup = bs4.BeautifulSoup(S, selfClosingTags=['bar'])
  
  print soup.prettify()
  </code></pre>
  
  <p>Does not self-close the <code>bar</code> tag, but gives a hint. What is this tree builder that bs4 is referring to and how to I self-close the tag?</p>
  
  <pre><code>/usr/local/lib/python2.7/dist-packages/bs4/__init__.py:112: UserWarning: BS4 does not respect the selfClosingTags argument to the BeautifulSoup constructor. The tree builder is responsible for understanding self-closing tags.
    "BS4 does not respect the selfClosingTags argument to the "
  &lt;html&gt;
   &lt;body&gt;
    &lt;foo&gt;
     &lt;bar a="3"&gt;
     &lt;/bar&gt;
    &lt;/foo&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>