Упрощенный пример xml:
Код: Выделить всё
Tove
Код: Выделить всё
Код: Выделить всё
@staticmethod
def replace_checksum_in_index_xml(infile, checksum_new, outfile):
from lxml import etree
parser = etree.XMLParser(remove_blank_text=True)
with open(infile, "rb") as f:
tree = etree.parse(f, parser)
for elem in tree.xpath("//to[@checksum]"):
elem.set("checksum", checksum_new)
with open(outfile, "wb") as f:
tree.write(f, pretty_print=True, xml_declaration=True, encoding="UTF-8", doctype=tree.docinfo.doctype)
Код: Выделить всё
infile = "Input.xml"
check_sum = "aaabbb"
outfile = "Output.xml"
Hashes.replace_checksum_in_index_xml(infile, check_sum, outfile)
Код: Выделить всё
Tove
DOCTYPE note:note
имеется
DOCTYPE примечание
Я хотел бы сохранить DOCTYPE в том виде, в каком он был.
Как я могу добиться желаемого результата в Python?
Подробнее здесь: https://stackoverflow.com/questions/793 ... ith-a-doct
Мобильная версия