File tree 2 files changed +35
-2
lines changed
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 144
144
145
145
local function parseEntities (self , s )
146
146
if self .options .expandEntities then
147
- -- for k,v in self._ENTITIES do
148
147
for k ,v in pairs (self ._ENTITIES ) do
149
- -- print (k, v)
150
148
s = string.gsub (s ,k ,v )
151
149
end
152
150
end
Original file line number Diff line number Diff line change
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 (" \n Manual print" )
28
+ for i , p in pairs (data ) do
29
+ print (" " .. i , p )
30
+ end
31
+
32
+ print (" \n Recursive print" )
33
+
34
+ -- Recursivelly prints the table in an easy-to-ready format
35
+ xml2lua .printable (handler .root )
You can’t perform that action at this time.
0 commit comments