File size: 3,328 Bytes
d7c5875 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | ---@module Handler to generate a simple event trace which
--outputs messages to the terminal during the XML
--parsing, usually for debugging purposes.
--
-- License:
-- ========
--
-- This code is freely distributable under the terms of the [MIT license](LICENSE).
--
--@author Paul Chakravarti (paulc@passtheaardvark.com)
--@author Manoel Campos da Silva Filho
local print = {}
---Parses a start tag.
-- @param tag a {name, attrs} table
-- where name is the name of the tag and attrs
-- is a table containing the atributtes of the tag
-- @param s position where the tag starts
-- @param e position where the tag ends
function print:starttag(tag, s, e)
io.write("Start : "..tag.name.."\n")
if tag.attrs then
for k,v in pairs(tag.attrs) do
io.write(string.format(" + %s='%s'\n", k, v))
end
end
end
---Parses an end tag.
-- @param tag a {name, attrs} table
-- where name is the name of the tag and attrs
-- is a table containing the atributtes of the tag
-- @param s position where the tag starts
-- @param e position where the tag ends
function print:endtag(tag, s, e)
io.write("End : "..tag.name.."\n")
end
---Parses a tag content.
-- @param text text to process
-- @param s position where the tag starts
-- @param e position where the tag ends
function print:text(text, s, e)
io.write("Text : "..text.."\n")
end
---Parses CDATA tag content.
-- @param text CDATA content to be processed
-- @param s position where the tag starts
-- @param e position where the tag ends
function print:cdata(text, s, e)
io.write("CDATA : "..text.."\n")
end
---Parses a comment tag.
-- @param text comment text
-- @param s position where the tag starts
-- @param e position where the tag ends
function print:comment(text, s, e)
io.write("Comment : "..text.."\n")
end
---Parses a DTD tag.
-- @param tag a {name, attrs} table
-- where name is the name of the tag and attrs
-- is a table containing the atributtes of the tag
-- @param s position where the tag starts
-- @param e position where the tag ends
function print:dtd(tag, s, e)
io.write("DTD : "..tag.name.."\n")
if tag.attrs then
for k,v in pairs(tag.attrs) do
io.write(string.format(" + %s='%s'\n", k, v))
end
end
end
--- Parse a XML processing instructions (PI) tag.
-- @param tag a {name, attrs} table
-- where name is the name of the tag and attrs
-- is a table containing the atributtes of the tag
-- @param s position where the tag starts
-- @param e position where the tag ends
function print:pi(tag, s, e)
io.write("PI : "..tag.name.."\n")
if tag.attrs then
for k,v in pairs(tag.attrs) do
io. write(string.format(" + %s='%s'\n",k,v))
end
end
end
---Parse the XML declaration line (the line that indicates the XML version).
-- @param tag a {name, attrs} table
-- where name is the name of the tag and attrs
-- is a table containing the atributtes of the tag
-- @param s position where the tag starts
-- @param e position where the tag ends
function print:decl(tag, s, e)
io.write("XML Decl : "..tag.name.."\n")
if tag.attrs then
for k,v in pairs(tag.attrs) do
io.write(string.format(" + %s='%s'\n", k, v))
end
end
end
return print
|