【发布时间】:2021-11-06 23:40:09
【问题描述】:
我正在尝试自动将翻译从一个 XML 文件替换为另一个。原始翻译将翻译设置在错误的文件中,我正在尝试通过自动化过程将其恢复。原始文件是这样的:
<version major="3" minor="6" revision="3" build="1" />
<region id="TranslatedStringKeys">
<node id="root">
<children>
<node id="TranslatedStringKey">
<attribute id="Content" type="28" handle="ls::TranslatedStringRepository::s_HandleUnknown" value="Spanish 1" />
<attribute id="ExtraData" type="23" value="" />
<attribute id="Speaker" type="22" value="" />
<attribute id="Stub" type="19" value="True" />
<attribute id="UUID" type="22" value="AAA" />
</node>
<node id="TranslatedStringKey">
<attribute id="Content" type="28" handle="ls::TranslatedStringRepository::s_HandleUnknown" value="Spanish 2" />
<attribute id="ExtraData" type="23" value="" />
<attribute id="Speaker" type="22" value="" />
<attribute id="Stub" type="19" value="True" />
<attribute id="UUID" type="22" value="BBB" />
</node>
</children>
</node>
</region>
<content contentuid="h5f6c914fg7db0g4763g9731g58a5eb60c6ab" Source="1.lsb" Key="AAA">English1</content>
<content contentuid="h95735cfdgc22cg4d38g9679ge071f18d77aa" Source="1.lsb" Key="BBB">English2</content>
我的目标是将 id="UUID" 属性中的属性 'value' 的值与每个 'content' 节点的 Key 进行比较,如果相同,则替换每个 'content' 的值' id="Content" 的属性中具有属性 'value' 的值的节点,因此它的结尾如下:
<content contentuid="h5f6c914fg7db0g4763g9731g58a5eb60c6ab" Source="1.lsb" Key="AAA">Spanish 1</content>
<content contentuid="h95735cfdgc22cg4d38g9679ge071f18d77aa" Source="1.lsb" Key="BBB">Spanish 2</content>
我曾尝试使用 C# 和 Xml.Linq 进行操作,但由于我的代码构建经验非常有限,因此我在构建代码时遇到了很多错误。
感谢您的帮助和时间
【问题讨论】: