29.05.2024, 06:30
Try this:
Code:
xml =[[<?xml version="1.0" encoding="utf-8"?>
<Response>
<Name>Login</Name>
<Parameters>
<Parameter name="Status" dataType="int">0</Parameter>
<Parameter name="StatusMessage" dataType="string">Successful</Parameter>
<Parameter name="UserID" dataType="int">1234</Parameter>
<Parameter name="Firstname" dataType="string">James</Parameter>
<Parameter name="AllowR1XTill" dataType="string">2023-06-30</Parameter>
</Parameters>
</Response>]]
parameters = {}
function starttag(parser, tag, attrs)
if tag == 'Parameter' then
name = attrs.name
end
end
function text(parser, text)
if name then
parameters[ name ] = text:trim()
name = nil
end
end
require('lxp').new({
StartElement = starttag,
CharacterData = text,
}):parse(xml)
log(parameters)
log(parameters.UserID)