Just create an empty object BeautifulSoup():
soup = BeautifulSoup()
and start adding items:
soup.append(soup.new_tag("a", href="http://www.example.com"))
For XML, you can start with the XML header using the tree constructor xml:
soup = BeautifulSoup(features='xml')
lxml. .is_xml BeautifulSoup ( ).