20.12.2022, 08:56
It makes more sense to find values by ID instead of position inside of the XML that can potentially change. Try this:
Code:
data = [[
<values>
<item id='0x8764bc'>
<item id='0x87676c'>
<value>32.5°C</value>
</item>
<item id='0x87de1c'>
<value>28.6°C</value>
</item>
<item id='0x87de64'>
<value>28.4°C</value>
</item>
<item id='0x876724'>
<value>62.7°C</value>
</item>
</item>
<item id='0x876504'>
<item id='0x8b7ab4'>
<value>Aan</value>
</item>
<item id='0x87e0d4'>
<value>Aan</value>
</item>
</item>
<item id='0x8765dc'>
<item id='0x878554'>
<value>Uit</value>
</item>
<item id='0x861b84'>
<value>Aan</value>
</item>
<item id='0x861bcc'>
<value>Aan</value>
</item>
<item id='0x87850c'>
<value>Aan</value>
</item>
</item>
</values>]]
function starttag(p, tag, attrs)
if tag == 'item' then
id = attrs.id
elseif tag == 'value' then
value = true
end
end
function endtag(p, tag)
if tag == 'item' then
id = nil
elseif tag == 'value' then
value = nil
end
end
function text(p, tdata)
if value and id then
values[ id ] = tdata
value = nil
end
end
values = {}
require('lxp').new({
StartElement = starttag,
EndElement = endtag,
CharacterData = text,
}):parse(data)
log(values)