Вместо этого я хотел бы дать имена каждого узла в пути, например, A/b/c.
У каждого узла есть атрибут имени, так что это может быть возможным, но я не уверен. Будьте очень ценят!
Код: Выделить всё
from xmldiff import main
from xmldiff.formatting import DiffFormatter
from lxml import etree
# Original Schema 1
with open("XSD_Original_Version.xsd", "r", encoding="utf-8") as file1:
schema1 = file1.read()
# Modified Schema 2
with open("XSD_SR_Version.xsd", "r", encoding="utf-8") as file2:
schema2 = file2.read()
# Parse the original schema into an ElementTree (needed by formatter)
orig_tree = etree.fromstring(schema1)
new_tree = etree.fromstring(schema2)
# Compute the diff operations
diff_ops = main.diff_trees(orig_tree, new_tree)
# Format the changes into readable text
formatter = DiffFormatter()
formatted_diff = formatter.format(diff_ops, orig_tree)
# Print the result
print("Changes from Schema1 to Schema2:\n")
for line in formatted_diff.splitlines():
if line.strip():
print(f"- {line}")
[*] [Update-attribute,/xs: schema/xs: complextype [7]/xs: element [15], name, "status"]
[*] [Обновление-аттриб "xs: String"]
[*] [Update-Text-after,/xs: schema/xs: complextype [7]/xs: element [15], "\ n \ t \ t"]
[*] [Move,/xs: schema/xs: complextype [6]/xs: выбор [2]. /xs: schema/xs: complextype [7], 15]
[*] [Update-attribute,/xs: schema/xs: complextype [7]/xs: element [16], имя, "Бизнеспол"]
[*] [Update-Text-after,/xs: schema/xs: xs. "\ n \ t \ t"]
[*] [move,/xs: schema/xs: complextype [6]/xs: выбор [2]/xs: выбор/xs: element [75],/xs: schema/xs: specbledtype [7], 16]
[*] [ /xs: schema/xs: complextype [7]/xs: element [17], name, "GeooCodestAtUsdisplay"]
[*] [Update-Text-after,/xs: schema/xs: spexttype [7]/xs: element [17], "\ n \ t \ t \ t"]
>. /> < /ul>
Не уверен, что поместить здесь < /p>
Подробнее здесь: https://stackoverflow.com/questions/797 ... f-nodes-in