(xml_path: Path, root_tag: str, content: str)
| 84 | |
| 85 | |
| 86 | def _append_xml(xml_path: Path, root_tag: str, content: str) -> None: |
| 87 | dom = defusedxml.minidom.parseString(xml_path.read_text(encoding="utf-8")) |
| 88 | root = dom.getElementsByTagName(root_tag)[0] |
| 89 | ns_attrs = " ".join(f'xmlns:{k}="{v}"' for k, v in NS.items()) |
| 90 | wrapper_dom = defusedxml.minidom.parseString(f"<root {ns_attrs}>{content}</root>") |
| 91 | for child in wrapper_dom.documentElement.childNodes: |
| 92 | if child.nodeType == child.ELEMENT_NODE: |
| 93 | root.appendChild(dom.importNode(child, True)) |
| 94 | output = _encode_smart_quotes(dom.toxml(encoding="UTF-8").decode("utf-8")) |
| 95 | xml_path.write_text(output, encoding="utf-8") |
| 96 | |
| 97 | |
| 98 | def _find_para_id(comments_path: Path, comment_id: int) -> str | None: |
no test coverage detected