纯 LuaXml 查找函数的等效函数

我正在尝试重新构建 luaxml 模块中的 find 函数。我有点卡壳了,这是我第一次尝试使用 lua。

这是 LuaXML 的工作方式:

require('LuaXml');

response= '<?xml version="1.0" encoding="ISO-8859-1"?> \
    <GeraeteAntwort AntwortType="Input" RequestID="2" Result="Success"> \
      <Output AusgabeDevice="Display"AusgabeResult="Success"></Output> \
      <Input Eingabe="Keyboard" EinResult="Success"> \
        <InputValue> \
          <InString>True</InString> \
        </InputValue> \
      </Input> \
    </GeraeteAntwort>'

local xfile = xml.eval(response)
local xInput = xfile:find("Input")
for k,v in pairs(xInput) do print(k,v) end

使用 find 函数的结果表,我可以用 xInput.Eingabe 访问 input 的属性(如 _Eingabe_)。现在来到了棘手的部分。我可以这样做:

local xIN = xInput:find("InputValue")

这会给我 InputValue 标记的属性。然后我可以用以下方式访问结果

xIN:find('InString')[1]

简短地说:我也可以在查找结果上进行查找。

这就是我不知道如何做的部分。

我使用了一个 XML 库进行解析,并尝试对其进行修改。 我将其上传到了 pastie

xfile = XL:new()
xfile:from_string(response)
local xInput = xfile:find("Input")

这使我能够访问输入的所有属性。但是我无法在此基础上进行另一个查找以获得 InputValue。

我该怎么办呢?

点赞