luaxmlモジュールfind
から関数を再構築しようとしています。私は少し立ち往生しています。これは、lua を使用した最初の試みの 1 つです。
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]
短い: 検索の結果に対して検索を実行することもできます。
やり方がわからない部分です。
解析に XML ライブラリを使用し、それを変更しようとしました。これをパスティにアップロードしました。
xfile = XL:new()
xfile:from_string(response)
local xInput = xfile:find("Input")
これにより、入力からすべての属性にアクセスできます。しかし、InputValue を取得するために別の検索を行うことはできません。
これどうやってするの?