Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion XmlParser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ end
--@param s String containing tag text
--@return a {name, attrs} table
-- where name is the name of the tag and attrs
-- is a table containing the atributtes of the tag
-- is a table containing the attributes of the tag
local function parseTag(self, s)
local tag = {
name = string.gsub(s, self._TAG, '%1'),
Expand Down
65 changes: 33 additions & 32 deletions xmlhandler/dom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ local function init()
end

--- @module Handler to generate a DOM-like node tree structure with
-- a single ROOT node parent - each node is a table comprising
-- a single ROOT node parent - each node is a table comprising
-- the fields below.
--
-- node = { _name = <Element Name>,
--
-- node = { _name = <ELEMENT Name>,
-- _type = ROOT|ELEMENT|TEXT|COMMENT|PI|DECL|DTD,
-- _text = <TEXT or COMMENT string>,
-- _attr = { Node attributes - see callback API },
-- _parent = <Parent Node>
-- _children = { List of child nodes - ROOT/NODE only }
-- _parent = <Parent Node>,
-- _children = { List of child nodes - ROOT/ELEMENT only }
-- }
-- where:
-- - PI = XML Processing Instruction tag.
Expand All @@ -24,7 +25,7 @@ end
--
-- Options
-- =======
-- options.(comment|pi|dtd|decl)Node = bool
-- options.(comment|pi|dtd|decl)Node = bool
-- - Include/exclude given node types
--
-- License:
Expand Down Expand Up @@ -52,15 +53,15 @@ end

---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
-- where name is the name of the tag and attrs
-- is a table containing the attributes of the tag
function dom:starttag(tag)
local node = { _type = 'ELEMENT',
_name = tag.name,
_attr = tag.attrs,
_children = {}
local node = { _type = 'ELEMENT',
_name = tag.name,
_attr = tag.attrs,
_children = {}
}

if self.root == nil then
self.root = node
end
Expand All @@ -73,8 +74,8 @@ 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
-- where name is the name of the tag and attrs
-- is a table containing the attributes of the tag
function dom:endtag(tag, s)
--Table representing the containing tag of the current tag
local prev = self._stack[#self._stack]
Expand All @@ -90,7 +91,7 @@ end
---Parses a tag content.
-- @param text text to process
function dom:text(text)
local node = { _type = "TEXT",
local node = { _type = "TEXT",
_text = text
}
table.insert(self.current._children, node)
Expand All @@ -100,50 +101,50 @@ end
-- @param text comment text
function dom:comment(text)
if self.options.commentNode then
local node = { _type = "COMMENT",
_text = text
local node = { _type = "COMMENT",
_text = text
}
table.insert(self.current._children, node)
end
end

--- Parses a XML processing instruction (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
-- where name is the name of the tag and attrs
-- is a table containing the attributes of the tag
function dom:pi(tag)
if self.options.piNode then
local node = { _type = "PI",
local node = { _type = "PI",
_name = tag.name,
_attr = tag.attrs,
}
_attr = tag.attrs,
}
table.insert(self.current._children, node)
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
-- where name is the name of the tag and attrs
-- is a table containing the attributes of the tag
function dom:decl(tag)
if self.options.declNode then
local node = { _type = "DECL",
_name = tag.name,
_attr = tag.attrs,
local node = { _type = "DECL",
_name = tag.name,
_attr = tag.attrs,
}
table.insert(self.current._children, node)
end
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
-- where name is the name of the tag and attrs
-- is a table containing the attributes of the tag
function dom:dtd(tag)
if self.options.dtdNode then
local node = { _type = "DTD",
local node = { _type = "DTD",
_name = tag.name,
_attr = tag.attrs,
_attr = tag.attrs,
}
table.insert(self.current._children, node)
end
Expand Down