I am trying to read and manipulate a XML feed from my Sat receiver to find the active channel
My Receiver gives as XML
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<deviceInfoTable>
<deviceInfo>
<ipAdress>XXX.XXX.XXX.XXX</ipAdress>
<productType>ufs923</productType>
<xmlInterfaceVersion>8</xmlInterfaceVersion>
<TVgenial>1</TVgenial>
<connectVersion>10</connectVersion>
<name>ufs923 (XXX.XXX.XXX.XXX)</name>
<VirtualStandBy>FALSE</VirtualStandBy>
<textInput>0</textInput>
<liveChannel>TV.2</liveChannel>
</deviceInfo>
</deviceInfoTable>
I found the XML Capture function
Code: Select all
function XML_Capture(cmd,flatten)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if flatten then
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
end
return s
end
XML_string=XML_Capture("curl -s 'http://XXX.XXX.XXX.XXX:9000/xmlfeeds/deviceInfo'",1)
I want to extract the "TV.2" from the string so:XML_string = XXX.XXX.XXX.XXX ufs923 8 1 10 ufs923 (XXX.XXX.XXX.XXX) FALSE 0 TV.2
valid = string.find(XML_string, "TV.")
valid returns 188
but when I change XML_string to the actual string(hardcoded):
valid = string.find("XXX.XXX.XXX.XXX ufs923 8 1 10 ufs923 (XXX.XXX.XXX.XXX) FALSE 0 TV.2", "TV.")
then valid returns 64 (Which is right!)
Where does the valid = 188 come from???
All help is welcome...
regards, Hans