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

toXml function returns with _att #39

Closed Roycohen closed 4 years ago

Roycohen commented 4 years ago

Hi There,

I'm using the toXml function but it returned with the <_attr> and it breaks the XML. Example:

local handler = require("xmlhandler.tree")

local parser = xml2lua.parser(handler)

local p = [[<people a="b" b="c">
  <person type="natural">
    <name>Manoel</name>
    <city>Palmas-TO</city>
  </person>
  <person type="natural">
    <name>Breno</name>
    <city>Palmas-TO</city>
  </person>
  <person type="legal">
    <name>University of Brasília</name>
    <city>Brasília-DF</city>
  </person>
</people>]]

parser:parse(p)

print(xml2lua.toXml(handler.root, 'level'))

Result:

<level>
<people>
**<2>**
  <person type="natural">
    <city>Palmas-TO</city>
    <name>Manoel</name>
  </person>
  <person type="natural">
    <city>Palmas-TO</city>
    <name>Breno</name>
  </person>
  <person type="legal">
    <city>Brasília-DF</city>
    <name>University of Brasília</name>
  </person>
**<_attr>
<3>
<b>c</b>
<a>b</a>
</3>

</_attr>
</2>**

</people>
</level>

As you can see something is broken. Appreciate your help here.

Roycohen commented 4 years ago

Moreover, take the toXml results from the test cases and convert them to tables and return them back to results see that it doesn't work. Please help...

Shelim commented 4 years ago

I run into the same problem. See my pull request for solution