My listener function looks like this:
[lua]
local function networkListener( event )
if ( event.isError ) then
print ( “Network error!”)
else
local xmltable=xml:ParseXmlText(event.response)
--print (event.response)
print (xmltable.child[1].child[1].child[1].value)
--print (xmltable.child[1].child[1].child[2].value)
end
end[/lua]
and the XML string being parsed is this:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<query xmlns:yahoo=“http://www.yahooapis.com/v1/base.rng” yahoo:count=“2” yahoo:created=“2014-02-07T02:07:33Z” yahoo:lang=“en-US”>
<results>
<quote>
<LastTradePriceOnly>107.45</LastTradePriceOnly>
</quote>
<quote>
<LastTradePriceOnly>97.82</LastTradePriceOnly>
</quote>
</results>
</query>
<!-- total: 92 -->
<!-- engine7.yql.bf1.yahoo.com -->
When I run my code, it seems to work erratically. Sometimes
print (xmltable.child[1].child[1].child[1].value)
gives me the answer I am looking for. Other times it blows up with an error in the terminal
Runtime error
…ers/seandzafovic/Desktop/Volume App 2/data_entry.lua:120: attempt to index field ‘?’ (a nil value)
stack traceback:
[C]: ?
…ers/seandzafovic/Desktop/Volume App 2/data_entry.lua:120: in function <…ers/seandzafovic/Desktop/Volume App 2/data_entry.lua:112>
Runtime error: …ers/seandzafovic/Desktop/Volume App 2/data_entry.lua:120: attempt to index field ‘?’ (a nil value)
stack traceback:
[C]: ?
…ers/seandzafovic/Desktop/Volume App 2/data_entry.lua:120: in function <…ers/seandzafovic/Desktop/Volume App 2/data_entry.lua:112>
Also, when I try and print (xmltable.child[1].child[1].child[2].value) it always gives the run time error.
Any ideas as to why this is happening?