code: def html_to_dom(html, default_encoding=DEFAULT_ENCODING, encoding=None, errors=DEFAULT_ENC_ERRORS):
      
      if isinstance(html, unicode):
          decoded_html = html
          # encode HTML for case it's XML with encoding declaration
          forced_encoding = encoding if encoding else default_encoding
          html = html.encode(forced_encoding, errors)
      else:
          decoded_html = decode_html(html, default_encoding, encoding, errors)
  
      try:
          dom = lxml.html.fromstring(decoded_html, parser=lxml.html.HTMLParser())
      except ValueError:
          # Unicode strings with encoding declaration are not supported.
          # for XHTML files with encoding declaration, use the declared encoding
          dom = lxml.html.fromstring(html, parser=lxml.html.HTMLParser())
  
      return dom
docs: Converts HTML to DOM.