格式化 XML 输出(移除声明、过滤空行)
(elem: ET.Element)
| 42 | |
| 43 | |
| 44 | def prettify_xml(elem: ET.Element) -> str: |
| 45 | """格式化 XML 输出(移除声明、过滤空行)""" |
| 46 | rough = ET.tostring(elem, encoding="utf-8").decode("utf-8") |
| 47 | try: |
| 48 | parsed = minidom.parseString(rough) |
| 49 | lines = parsed.toprettyxml(indent=" ").split("\n") |
| 50 | return "\n".join( |
| 51 | line for line in lines |
| 52 | if line.strip() and not line.strip().startswith("<?xml") |
| 53 | ) |
| 54 | except Exception: |
| 55 | return rough |
| 56 | |
| 57 | |
| 58 | def parse_drawio_xml(path_or_string: str) -> ET.Element: |
nothing calls this directly
no outgoing calls
no test coverage detected