manoelcampos / xml2lua

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

Using toXml() with 2 same-name child tags fails. #45

Closed fordcars closed 4 years ago

fordcars commented 4 years ago

Hi! I've been testing out this library, and I've been having trouble with a certain combination of tags:

<Game>
    <resources>
        <object>
            <path>myFirstPath</path>
            <path>mySecondPath</path>
        </object>
    </resources>
</Game>`

Here, when parsed using xml2lua.parser(handler), I get an array like this:

{ ["Game"] =  {
    ["resources"] = {
        ["object"] = {
            ["path"] = {
                [1] = "myFirstPath",
                [2] = "mySecondPath"
             } 
         }
     } 
}

... which is what I expected. However, when I simply put that array back into xml2lua.toXml(), I get the following output:

<Game>
  <resources>
      <object>
                          <1>myFirstPath</1>
              <2>mySecondPath</2>
      </object>
  </resources>
</Game>

Is there anything I am doing wrong? Thank you!

Lua vesion. 5.3.2 System: Ubuntu 18.04.4 LTS

manoelcampos commented 4 years ago

Hello @fordcars Just fixed the issue. Thanks for reporting.

manoelcampos commented 4 years ago

Try the new 1.4-1 version. It's in luarocks already.