从 XML 文件中读取值并将其分配给变量

我是新来的,希望有人能帮我解决我的问题。 使用这段代码,我逐行读取 XML 文件。

      if counter == 8 then
            file = io.open("e:\\Temp\\Flusis\\FlugDaten.xml", "r")
            line=file:read("*l")
            i=1
            txt={}
            while line~=nil do
                txt[i]=line
                    if i == 3 then
                        local a, b, c = string.match( "(.*)>(.*)</(.*)" )
                        simulator = b
                        print("Sim: ", simulator)
                    end
                i=i+1
                line=file:read("*l")
            end
            file:close()
            counter = counter + 1
        end

在其中,我从我的 XML 文件中找到了这个文本。enter image description here 我尝试提取 MSFS20,并将这个值分配给变量模拟器。 但当这个脚本运行时,它总是导致这个错误。 bad argument #2 to 'match' (string expected, got no value)

我尝试了很多,用 string.find、string.gmatch 等方法来解决它,但都没用。 希望有人能帮我解决我的问题。

非常感谢! Joachim

点赞