1
0
forked from 0ad/0ad

Simplify XML parsing by iterating only once

This simplifies the XML parsing, by iterating over the DOM tree only
once. Curiously this doesn't result in significant performance gains.

As the keywords are now found in the order they appear in the
document instead of the order they are mentioned in messages.json, the
order of a few strings in the PO-templates changes caused by the changes
in this commit.
This commit is contained in:
Dunedan 2024-09-07 06:38:54 +02:00
parent eeb502c115
commit 0e84957979
Signed by untrusted user: Dunedan
GPG Key ID: 885B16854284E0B2

View File

@ -452,8 +452,10 @@ class XmlExtractor(Extractor):
def extract_from_file(self, filepath):
with open(filepath, encoding="utf-8-sig") as file_object:
xml_document = etree.parse(file_object)
for keyword in self.keywords:
for element in xml_document.iter(keyword):
for element in xml_document.iter(*self.keywords.keys()):
keyword = element.tag
lineno = element.sourceline
if element.text is None:
continue
@ -476,7 +478,7 @@ class XmlExtractor(Extractor):
comment = element.get("comment")
comment = " ".join(
comment.split()
) # Remove tabs, line breaks and unecessary spaces.
) # Remove tabs, line breaks and unnecessary spaces.
comments.append(comment)
if "splitOnWhitespace" in self.keywords[keyword]:
for split_text in element.text.split():