Jianw
2025-05-13 b21510ffde25ef027d63862212495ac43b35b10f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env lua
-- Read XML documents containing DOCTYPE and CDATA tags,
-- parse with the dom parser,
-- print the XML documents to STDOUT.
local xml2lua = require("xml2lua")
local xmlhandler = require("xmlhandler.dom")
 
local files = {"books.xml", "people2.xml"}
for _, file in ipairs(files) do
   print(file, "-----------------------------------------------------------")
   local xml = xml2lua.loadFile(file)
   local dom = xmlhandler:new()
   local parser = xml2lua.parser(dom)
   parser:parse(xml)
   if not dom.root then
      print("parsing ", file , " as XML failed")
   else
      print(dom:toXml(dom.root))
   end
end