1

我正在尝试从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 函数的结果表,我可以访问input(如Eingabe) 的属性xInput.Eingabe。现在是棘手的部分。我可以:

local xIN = xInput:find("InputValue")

这给了我 InputValue 标签的属性。然后我可以访问结果

xIN:find('InString')[1]

Short:我也可以对查找的结果进行查找。

这是我不知道该怎么做的部分。

我使用 XML 库进行解析并尝试对其进行修改。我把这个上传到了一个馅饼上。

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

这使我可以访问 Input 中的所有属性。但我无法再找到它来获取 InputValue。

我怎样才能做到这一点?

4

0 回答 0