manoelcampos / xml2lua

XML Parser written entirely in Lua that works for Lua 5.1+. Convert XML to and from Lua Tables 🌖💱
MIT License
290 stars 74 forks source link

How do I synthesize an xml object that has both attributes and values? #101

Open Crazyokd opened 1 month ago

Crazyokd commented 1 month ago

with below code:

local people = {
    command_code="Authentication-Information-Request",
    applicationId="3GPP S6a/S6d",
    ["Hop-by-Hop"] = "0x5dd1330b",
    avp = {
        ["Session-Id"] = {
            _attr = {type = "string", vendor = "0"},
        },
    }
}
print("XML Representation\n")
print(xml2lua.toXml(people, "root"))

I can get below result:

XML Representation

<root>
  <Hop-by-Hop>0x5dd1330b</Hop-by-Hop>
  <command_code>Authentication-Information-Request</command_code>
  <applicationId>3GPP S6a/S6d</applicationId>
  <avp>
    <Session-Id>dfslk</Session-Id>
    <Session-Id>
      <vendor>0</vendor>
      <type>string</type>
    </Session-Id>
  </avp>
</root>

But I want synthesize <Session-Id type="string" vendor="0">846</Session-Id> i tried various method, but all can't work.