C:\Users\mangfu> python Python 3.8.7 (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from xml.etree import ElementTree >>> with open(r'C:\Users\mangfu\Downloads\1月_979a496e-9222-4eac-937f-9707b4d875b8.xml', encoding='utf-8') as f: ... root_element = ElementTree.parse(f).getroot() ... Traceback (most recent call last): File "<stdin>", line 2, in <module> File "E:\python3.8.7\lib\xml\etree\ElementTree.py", line 1202, in parse tree.parse(source, parser) File "E:\python3.8.7\lib\xml\etree\ElementTree.py", line 595, in parse self._root = parser._parse_whole(source) xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 207, column 178 >>>
# 处理 xml 文件 if xml_path.is_file(): file_content = replace_xml_special_characters(xml_path.read_text()) xml_path.write_text(file_content)
# 处理 xml 目录 elif xml_path.is_dir(): for sub_xml_path in xml_path.glob("*.xml"): file_content = replace_xml_special_characters(sub_xml_path.read_text()) sub_xml_path.write_text(file_content)
# 处理 xml 文件 if xml_path.is_file(): file_content = replace_xml_special_characters(xml_path.read_text()) xml_path.write_text(file_content)
# 处理 xml 目录 elif xml_path.is_dir(): for sub_xml_path in xml_path.glob("*.xml"): file_content = replace_xml_special_characters(sub_xml_path.read_text()) sub_xml_path.write_text(file_content)