3

I've gotten to where I can get the element values I want and append them to a txt file. The problem I'm having is appending them sequentially. An excerpt/sample from my xml file is:

<?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>

The output I would like to see is:

t1 s1 g1
t2 s2 g2
t3 s3 g3

My baseline script:

#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
}

Which results in:

t1 t2 t3 s1 s2 s3
g1
g2
g3

I've tried moving the close 'curly brackets' around and also the FileAppend similar to:

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
}

..which gives me:

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
...

And a few other iterations. I know (or at least feel) I'm on the right track and if this were the MasterMind game, I think I might have it by now. :) Alas, it's not.

Any help and guidance would be appreciated.

JoeViking
  • 55
  • 1
  • 6

1 Answers1

2

The easiest thing is probably doing it game by game, for example:

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
}
scso
  • 415
  • 7
  • 9