I have an xml file structured like the following:
Code: Select all
<triggers>
<trigger enabled="y" match="Some lines of text" sequence="100" regexp="n" ... ></trigger>
</triggers>
<aliases>
<alias enabled="y" match="Some more lines of text" sequence="100" regexp="n" ...></aliases>
Code: Select all
ParseFile(file) {
; Read the file contents
fileContent := FileRead(file)
currentElement := ""
; Prepare an empty array to store the elements
elements := Array()
; Loop over each line in the file content
for each, line in StrSplit(fileContent, "`n", "`r") {
; If the line contains the start of an element, create a new dictionary
if (RegExMatch(line, "i)<(trigger|alias|timer|variable)", &elementName)) {
currentElement := {type: elementName[1]} ; the '1' after elementName gets the first capture group
elements.Push(currentElement)
}
; If the line contains an attribute, add it to the current element
if !currentElement = "" {
if (RegExMatch(line, "i)(\w+)=`"(.*?)`"", &attribute)) {
currentElement[attribute[1]] := attribute[2]
}
}
; If the line contains the end of an element, stop adding attributes to it
if (RegExMatch(line, "i)</(trigger|alias|timer|variable)>")) {
currentElement := ""
}
}
}
Code: Select all
Triggers -
"Some line of text" -
enabled = "y"
sequence = "100"
regexp = "n"
Aliases -
"Some more lines of text" -
enabled ="y"
sequence = "100"
regexp = "n"