10.03.2023, 10:02
You can use lxp library to parse the XML:
There's no library for creating XML. For simple formats you can use raw strings:
Code:
xml = [[<?xml version="1.0" encoding="utf-8"?>
<stuMessages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://cody.glpconnect.com/XSD/StuMessage_Rev1_0.xsd" timeStamp="27/08/2009
21:00:00 GMT" messageID="56bdca48088610048fddba385e1cd5b8">
<stuMessage>
<esn>0-99990</esn>
<unixTime>1034268516</unixTime>
<gps>N</gps>
<payload length="9" source="pc" encoding="hex">0xC0560D72DA4AB2445A</payload>
</stuMessage>
</stuMessages>
]]
require('lxp').new({
StartElement = function(parser, tag, attrs)
if tag == 'stuMessages' then
timestamp = attrs.timeStamp
messageid = attrs.messageID
end
end
}):parse(xml)
log(timestamp)
log(messageid)
There's no library for creating XML. For simple formats you can use raw strings:
Code:
timestamp = '27/08/2009 21:00:00 GMT'
messageid = '56bdca48088610048fddba385e1cd5b8'
xml = [[<?xml version="1.0" encoding="utf-8"?>
<stuResponseMsg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://cody.glpconnect.com/XSD/StuResponse_Rev1_0.xsd"
deliveryTimeStamp="]] .. timestamp .. [[" correlationID="]] .. messageid .. [[">
<state>pass</state>
<stateMessage>Store OK</stateMessage>
</stuResponseMsg>]]