lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I try to use lxp.lom to parse xml file, but it gives empty table. Here is the code:
-- setup XML parser
local lom = require "lxp.lom"

--define global variables
tbl = {}
customer_cnt = 1

function initialize()
-- create a file handle to the file
local handle = io.open("testxml.xml","r")
  
-- read and parse the XML document
tbl = lom.parse(handle:read("*a"))
handle:close()
end;

When I try to print out tbl[1][1]:
 
io.write(tostring(tbl[1][cusomer_cnt]))

the print out result is:  nil
 
testxml.xml file:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Customers>
<Customer CustomerID="XYZ">
<CompanyName>XYZ Market</CompanyName>
<ContactName>John Doe</ContactName>
<ContactTitle>Marketing Manager</ContactTitle>
<Phone>(212) 555-1212</Phone>
<FullAddress>
<Address>100 Park Avenue.</Address>
<City>New York</City>
<State>NY</State>
</FullAddress>
</Customer>
</Customers>
</Root>
 
Not sure what I did incorrectly here, I would like to get some help. Thank you very much!
 
Jim