class_docstr: Class for formatting data in xml using Python standard library
  modules: `xml.etree.ElementTree` and `xml.dom.minidom`.
docstr: Build tree from  data.
  
  This method initializes the root and builds attributes and elements
  with optional namespaces.
docstr_tok: ["Build","tree","from","data",".","This","method","initializes","the","root","and","builds","attributes","and","elements","with","optional","namespaces","."]
code: def build_tree(self) -> bytes:
      """
      Build tree from  data.
  
      This method initializes the root and builds attributes and elements
      with optional namespaces.
      """
      from lxml.etree import (
          Element,
          SubElement,
          tostring,
      )
  
      self.root = Element(
          f"{self.prefix_uri}{self.root_name}", nsmap=self.namespaces
      )
  
      for d in self.frame_dicts.values():
          elem_row = SubElement(
              self.root, f"{self.prefix_uri}{self.row_name}"
          )
  
          if not self.attr_cols and not self.elem_cols:
              self.elem_cols = list(d.keys())
              self.build_elems(d, elem_row)
  
          else:
              elem_row = self.build_attribs(d, elem_row)
              self.build_elems(d, elem_row)
  
      self.out_xml = tostring(
          self.root,
          pretty_print=self.pretty_print,
          method="xml",
          encoding=self.encoding,
          xml_declaration=self.xml_declaration,
      )
  
      if self.stylesheet is not None:
          self.out_xml = self.transform_doc()
  
      return self.out_xml
  
imports: from __future__ import annotations
  import codecs
  import io
  from typing import TYPE_CHECKING, Any
  from pandas._typing import CompressionOptions, FilePath, ReadBuffer, StorageOptions, WriteBuffer
  from pandas.errors import AbstractMethodError
  from pandas.util._decorators import doc
  from pandas.core.dtypes.common import is_list_like
  from pandas.core.dtypes.missing import isna
  from pandas.core.shared_docs import _shared_docs
  from pandas.io.common import get_handle
  from pandas.io.xml import get_data_from_filepath, preprocess_data
label_desc: Use image node_id 2 for calling the LxmlXMLFormatter obj's underlying member method code with example usage: obj.build_tree() and returns: self