MCPcopy Create free account
hub / github.com/BIT-DataLab/Edit-Banana / prettify_xml

Function prettify_xml

modules/utils/xml_utils.py:44–55  ·  view source on GitHub ↗

格式化 XML 输出(移除声明、过滤空行)

(elem: ET.Element)

Source from the content-addressed store, hash-verified

42
43
44def 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
58def parse_drawio_xml(path_or_string: str) -> ET.Element:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected