lua表什么都不返回

时间:2014-01-02 04:00:29

标签: xml lua-table

尝试解析来自NWS网站的xml数据。

function block_weather_feed()
nws_xml_url="http://w1.weather.gov/xml/current_obs/KLNK.xml"
nws_xml=http.request(nws_xml_url)

local nws_table={}
current_tag=''

callbacks = {
    StartElement = function (parser, name)
        print ("+ ", name," ",current_tag, "\n")
        current_tag=name
    end,
    EndElement = function (parser, name)
        print ("- ", name," ",current_tag, "\n")
    end,
    CharacterData = function (parser, string)
        print ("* ", string," ",current_tag, "\n")
        nws_table[current_tag]=string
    end
}
nws_parse=lxp.new(callbacks)
nws_parse:parse(nws_xml)
nws_parse:close()
print (nws_xml)
for key,value in pairs(nws_table) do 
    print(key,"--",value) 
end
end

当我在表中循环时,键存在,但值不是。任何线索,为什么...如果我改变

nws_table[current_tag]=string

nws_table[#nws_table+1]=string

价值在那里,但没有字典,这些价值毫无意义。

0 个答案:

没有答案