[[+content_image]]
S
S
sergey_fs2018-05-09 00:26:08
Lua
sergey_fs, 2018-05-09 00:26:08

Unable to spread xml?

good afternoon, help parse xml
code written in LUA

require('xmlreader')
local xml =[[
<?xml version="1.0" encoding="utf-8"?>
<recognitionResults success="1">
  <variant confidence="0">нет спасибо</variant>
  <variant confidence="0.1">нет спасибо</variant>
</recognitionResults>
]]

local r = assert(xmlreader.from_string(xml))
while (r:read()) do
    local leadingws = ('    '):rep(r:depth())
    if (r:node_type() == "element") then
        io.write(("%s%s:"):format(leadingws, r:name()))
        while (r:move_to_next_attribute()) do
            io.write((' %s=%q'):format(r:name(), r:value()))
        end
        io.write('\n')
    end
end

when executing
[[email protected]_master scripts]# lua test_yandex.lua
recognitionResults: success="1"
variant: confidence="0"
variant: confidence="0.1"
but the question is how do I get to the text "No thanks"

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
F
Farwisdomer, 2018-05-09
@Farwisdomer

https://github.com/duhoobo/lua-xpath
and parse with XPath.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question