Build tree from data. This method initializes the root and builds attributes and elements with optional namespaces.
(self)
| 453 | self._convert_empty_str_key() |
| 454 | |
| 455 | def _build_tree(self) -> bytes: |
| 456 | """ |
| 457 | Build tree from data. |
| 458 | |
| 459 | This method initializes the root and builds attributes and elements |
| 460 | with optional namespaces. |
| 461 | """ |
| 462 | from lxml.etree import ( |
| 463 | Element, |
| 464 | SubElement, |
| 465 | tostring, |
| 466 | ) |
| 467 | |
| 468 | self.root = Element(f"{self.prefix_uri}{self.root_name}", nsmap=self.namespaces) |
| 469 | |
| 470 | for d in self.frame_dicts.values(): |
| 471 | elem_row = SubElement(self.root, f"{self.prefix_uri}{self.row_name}") |
| 472 | |
| 473 | if not self.attr_cols and not self.elem_cols: |
| 474 | self.elem_cols = list(d.keys()) |
| 475 | self._build_elems(d, elem_row) |
| 476 | |
| 477 | else: |
| 478 | elem_row = self._build_attribs(d, elem_row) |
| 479 | self._build_elems(d, elem_row) |
| 480 | |
| 481 | self.out_xml = tostring( |
| 482 | self.root, |
| 483 | pretty_print=self.pretty_print, |
| 484 | method="xml", |
| 485 | encoding=self.encoding, |
| 486 | xml_declaration=self.xml_declaration, |
| 487 | ) |
| 488 | |
| 489 | if self.stylesheet is not None: |
| 490 | self.out_xml = self._transform_doc() |
| 491 | |
| 492 | return self.out_xml |
| 493 | |
| 494 | def _convert_empty_str_key(self) -> None: |
| 495 | """ |
nothing calls this directly
no test coverage detected