Thanks to a previous answer in this wonderful forum, I managed to begin my little project where I want to iterate over an XML file.
My question this time regards how to get the ancestor node of one node I am already in through my for loop.
Can I somehow jump from the variable „Einzelkommentar“ to an ancestor node? What I need to do is find the nearest ancestor node of „Einzelkommentar“ (or simply the node „Comment“) which contains an attribute called „id“.
Also, could somebody please explain to me why the last iteration in the code works, regarding “nurname”? What it does is taking the entire file name and thus only giving out the file name without any of the previous items. It works but I really don’t understand why: if I change “Filename0” to “Filename1” it doesn’t work for example anymore. Also, why do I have to write “Filename%nurname%”, what das that do?
Please find my code below.
Code: Select all
FileEncoding, UTF-8
Filelocation := "C:\Users\rschuber\Desktop\XML in AHK\Hamlet.sdlxliff"
StringSplit, Filename, Filelocation, \
FileRead, xmldata, %Filelocation%
xmldata := StrReplace(xmldata,"xmlns=","QWERTYrandomweathering=")
doc := ComObjCreate("MSXML2.DOMDocument.6.0")
doc.async := false
doc.loadXML(xmldata)
AlleKommentare := doc.selectNodes("//Comment")
oExcel := ComObjCreate("Excel.Application")
oExcel.Workbooks.Add
increase := 1
For Einzelkommentar in AlleKommentare
{
jeder := Einzelkommentar["text"]
oExcel.Cells(increase,1).Value := jeder
ida := Einzelkommentar.getAttribute("date")
StringTrimRight, ida, ida, 14
ida := StrReplace(ida, "T", "`n") ; die Uhrzeit wird mit Linebreak geschrieben
oExcel.Cells(increase,2).Value := ida
usera := Einzelkommentar.getAttribute("user")
oExcel.Cells(increase,3).Value := usera
nurname := Filename0
oExcel.Cells(increase,4).Value := Filename%nurname%
increase += 1
}
oExcel.Worksheets(1).ListObjects.Add
oExcel.Cells(1,1).Value := "Comment"
oExcel.Cells(1,2).Value := "Date"
oExcel.Cells(1,3).Value := "User"
oExcel.Cells(1,4).Value := "Filename"
oExcel.Visible := 1
ExitApp
Code: Select all
<cmt-defs>
<cmt-def id="c894f2ce-599c-4b07-a685-734a67e25ac4">
<Comments>
<Comment severity="Low" user="PC" date="2016-11-07T21:54:25.1610721+00:00" version="1.0">Comment 1 on "Frage"</Comment>
</Comments>
Code: Select all
<mrk mtype="seg" mid="1">Sein oder Nichtsein; das ist hier die
<mrk mtype="x-sdl-comment" sdl:cid="c894f2ce-599c-4b07-a685-734a67e25ac4">
<mrk mtype="x-sdl-deleted" sdl:revid="ccc64fec-0fcb-447d-8803-ff4f2f26ccc9">
<mrk mtype="x-sdl-comment" sdl:cid="c894f2ce-599c-4b07-a685-734a67e25ac4">Frage</mrk>
</mrk>
<mrk mtype="x-sdl-added" sdl:revid="8753f05b-628b-4c1b-b33b-f9ea9961e06c">I just deleted "Frage", but the comment flag is still in</mrk>
</mrk>: