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

Attempt to index field '_attr' (a nil value) #9

Closed albrela closed 6 years ago

albrela commented 6 years ago

Hello manoel,

refering to the example in How-To-Use

If i try to use it and I have just one child in the node

local xml = [[
<people>
  <person type="P">
    <name>Manoel</name>
    <city>Palmas-TO</city>
  </person>
<!--  <person type="J"> -->
<!--    <name>University of Brasília</name> -->
<!--    <city>Brasília-DF</city> -->
<!--  </person> --> 
</people>    
]]

so I got this

Exception in thread "main" com.naef.jnlua.LuaRuntimeException: ...main.lua:41: attempt to index field '_attr' (a nil value)

Can you provide a solution for this?

Thank you for your attention.

Lars

manoelcampos commented 6 years ago

The issue was not related to xml2lua module, but the way Lua handles tables and arrays. Check the updated How to Use section, which links to example1.lua.

albrela commented 6 years ago

Thank you for this.