@@ -7,14 +7,15 @@ local function init()
77end
88
99--- @module Handler to generate a DOM-like node tree structure with
10- -- a single ROOT node parent - each node is a table comprising
10+ -- a single ROOT node parent - each node is a table comprising
1111-- the fields below.
12- --
13- -- node = { _name = <Element Name>,
12+ --
13+ -- node = { _name = <ELEMENT Name>,
1414-- _type = ROOT|ELEMENT|TEXT|COMMENT|PI|DECL|DTD,
15+ -- _text = <TEXT or COMMENT string>,
1516-- _attr = { Node attributes - see callback API },
16- -- _parent = <Parent Node>
17- -- _children = { List of child nodes - ROOT/NODE only }
17+ -- _parent = <Parent Node>,
18+ -- _children = { List of child nodes - ROOT/ELEMENT only }
1819-- }
1920-- where:
2021-- - PI = XML Processing Instruction tag.
2425--
2526-- Options
2627-- =======
27- -- options.(comment|pi|dtd|decl)Node = bool
28+ -- options.(comment|pi|dtd|decl)Node = bool
2829-- - Include/exclude given node types
2930--
3031-- License:
5253
5354--- Parses a start tag.
5455-- @param tag a {name, attrs} table
55- -- where name is the name of the tag and attrs
56- -- is a table containing the atributtes of the tag
56+ -- where name is the name of the tag and attrs
57+ -- is a table containing the attributes of the tag
5758function dom :starttag (tag )
58- local node = { _type = ' ELEMENT' ,
59- _name = tag .name ,
60- _attr = tag .attrs ,
61- _children = {}
59+ local node = { _type = ' ELEMENT' ,
60+ _name = tag .name ,
61+ _attr = tag .attrs ,
62+ _children = {}
6263 }
63-
64+
6465 if self .root == nil then
6566 self .root = node
6667 end
7374
7475--- Parses an end tag.
7576-- @param tag a {name, attrs} table
76- -- where name is the name of the tag and attrs
77- -- is a table containing the atributtes of the tag
77+ -- where name is the name of the tag and attrs
78+ -- is a table containing the attributes of the tag
7879function dom :endtag (tag , s )
7980 -- Table representing the containing tag of the current tag
8081 local prev = self ._stack [# self ._stack ]
9091--- Parses a tag content.
9192-- @param text text to process
9293function dom :text (text )
93- local node = { _type = " TEXT" ,
94+ local node = { _type = " TEXT" ,
9495 _text = text
9596 }
9697 table.insert (self .current ._children , node )
@@ -100,50 +101,50 @@ end
100101-- @param text comment text
101102function dom :comment (text )
102103 if self .options .commentNode then
103- local node = { _type = " COMMENT" ,
104- _text = text
104+ local node = { _type = " COMMENT" ,
105+ _text = text
105106 }
106107 table.insert (self .current ._children , node )
107108 end
108109end
109110
110111--- Parses a XML processing instruction (PI) tag
111112-- @param tag a {name, attrs} table
112- -- where name is the name of the tag and attrs
113- -- is a table containing the atributtes of the tag
113+ -- where name is the name of the tag and attrs
114+ -- is a table containing the attributes of the tag
114115function dom :pi (tag )
115116 if self .options .piNode then
116- local node = { _type = " PI" ,
117+ local node = { _type = " PI" ,
117118 _name = tag .name ,
118- _attr = tag .attrs ,
119- }
119+ _attr = tag .attrs ,
120+ }
120121 table.insert (self .current ._children , node )
121122 end
122123end
123124
124125--- Parse the XML declaration line (the line that indicates the XML version).
125126-- @param tag a {name, attrs} table
126- -- where name is the name of the tag and attrs
127- -- is a table containing the atributtes of the tag
127+ -- where name is the name of the tag and attrs
128+ -- is a table containing the attributes of the tag
128129function dom :decl (tag )
129130 if self .options .declNode then
130- local node = { _type = " DECL" ,
131- _name = tag .name ,
132- _attr = tag .attrs ,
131+ local node = { _type = " DECL" ,
132+ _name = tag .name ,
133+ _attr = tag .attrs ,
133134 }
134135 table.insert (self .current ._children , node )
135136 end
136137end
137138
138139--- Parses a DTD tag.
139140-- @param tag a {name, attrs} table
140- -- where name is the name of the tag and attrs
141- -- is a table containing the atributtes of the tag
141+ -- where name is the name of the tag and attrs
142+ -- is a table containing the attributes of the tag
142143function dom :dtd (tag )
143144 if self .options .dtdNode then
144- local node = { _type = " DTD" ,
145+ local node = { _type = " DTD" ,
145146 _name = tag .name ,
146- _attr = tag .attrs ,
147+ _attr = tag .attrs ,
147148 }
148149 table.insert (self .current ._children , node )
149150 end
0 commit comments