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 ="testxml.xml","r")
-- read and parse the XML document
tbl = lom.parse(handle:read("*a"))

When I try to print out tbl[1][1]:

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