Skip to content

Commit 8a9da53

Browse files
committed
Adds example3 and removes dead comments from XmlParser
1 parent f419497 commit 8a9da53

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

XmlParser.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ end
144144

145145
local function parseEntities(self, s)
146146
if self.options.expandEntities then
147-
--for k,v in self._ENTITIES do
148147
for k,v in pairs(self._ENTITIES) do
149-
--print (k, v)
150148
s = string.gsub(s,k,v)
151149
end
152150
end

example3.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env lua
2+
3+
---Sample application to read a XML file and print it on the terminal.
4+
--This example shows how the module deals with duplicated XML tags,
5+
--either if they have a value or not.
6+
--Use of of the XML below and comment the other ones to see the difference
7+
--@author Manoel Campos da Silva Filho - http://manoelcampos.com
8+
9+
local xml2lua = require("xml2lua")
10+
--Uses a handler that converts the XML to a Lua table
11+
local handler = require("xmlhandler.tree")
12+
13+
--local xml = "<tag><tag1/></tag>"
14+
--local xml = "<tag><tag1/><tag1/></tag>"
15+
--local xml = "<tag><tag1>A</tag1><tag1>B</tag1></tag>"
16+
local xml = "<tag><tag1>A</tag1></tag>"
17+
18+
--Instantiates the XML parser
19+
local parser = xml2lua.parser(handler)
20+
parser:parse(xml)
21+
22+
local data = handler.root.tag
23+
if #data.tag1 > 1 then
24+
data = data.tag1
25+
end
26+
27+
print("\nManual print")
28+
for i, p in pairs(data) do
29+
print(" " .. i, p)
30+
end
31+
32+
print("\nRecursive print")
33+
34+
--Recursivelly prints the table in an easy-to-ready format
35+
xml2lua.printable(handler.root)

0 commit comments

Comments
 (0)