AHK 将多个 xml 元素依次解析成 [.txt] 文件

AHK Parse multiple xml elements in sequence into [.txt] file

我已经找到可以获取所需元素值并将它们附加到 txt 文件的位置。我遇到的问题是按顺序附加它们。我的 xml 文件中的 excerpt/sample 是:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Arcade>
  <Game>
    <Title>t1</Title>
    <Publisher>p1</Publisher>
    <Source>s1</Source>
    <Version>v1</Version>
    <Genre>g1</Genre>
  </Game>
  <Game>
    <Title>t2</Title>
    <Publisher>p2</Publisher>
    <Source>s2</Source>
    <Version>v2</Version>
    <Genre>g2</Genre>
  </Game>
  <Game>
    <Title>t3</Title>
    <Publisher>p3</Publisher>
    <Source>s3</Source>
    <Version>v3</Version>
    <Genre>g3</Genre>
  </Game>
</Arcade>

我希望看到的输出是:

t1 s1 g1
t2 s2 g2
t3 s3 g3

我的基准脚本:

#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

xmlPath := "D:\temp\Arcade.xml"
xmlDoc := ComObjCreate("MSXML2.DOMDocument.6.0")
xmlDoc.async := false
xmlDoc.load(xmlPath)

Loop Files, %xmlPath%
{
    for item in xmlDoc.getElementsByTagName("Title") {
        Tstring := item.text
        FileAppend, %Tstring% , D:\temp\testoutput.txt
        }
    for item in xmlDoc.getElementsByTagName("Source") {
        Sstring := item.text
        FileAppend, %Sstring% , D:\temp\testoutput.txt
        }
    for item in xmlDoc.getElementsByTagName("Genre") {
        Gstring := item.text
        FileAppend, %Gstring%`n, D:\temp\testoutput.txt
        }
ExitApp
}

这导致:

t1 t2 t3 s1 s2 s3
g1
g2
g3

我试过移动关闭 'curly brackets' 和 FileAppend 类似于:

Loop Files, %xmlPath%
{
    for item in xmlDoc.getElementsByTagName("Title") {
        Tstring := item.text
    for item in xmlDoc.getElementsByTagName("Source") {
        Sstring := item.text
    for item in xmlDoc.getElementsByTagName("Genre") {
        Gstring := item.text
        FileAppend, %Tstring%|%Sstring%|%Gstring%`n, D:\temp\testoutput.txt
        }
        }
        }
ExitApp
}

..这给了我:

t1 s1 g1
t1 s1 g2
t1 s1 g3
t1 s2 g1
t1 s2 g2
t1 s2 g3
t1 s3 g1
t1 s3 g2
t1 s3 g3
t2 s1 g1
t2 s1 g2
t2 s1 g3
...

以及其他一些迭代。我知道(或者至少感觉)我走在正确的轨道上,如果这是 MasterMind 游戏,我想我现在可能已经拥有了。 :) 唉,不是。

如有任何帮助和指导,我们将不胜感激。

最简单的可能是一个游戏一个游戏地做,例如:

for Game in xmlDoc.getElementsByTagName("Game") {
    Text := ""
    Text .= Game.getElementsByTagName("Title").item(0).text
    Text .= Game.getElementsByTagName("Source").item(0).text
    Text .= Game.getElementsByTagName("Genre").item(0).text
    MsgBox % Text
}