Skip to content

Add option to replace hyphens with underscore in tag names #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion XmlParser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ end
-- where name is the name of the tag and attrs
-- is a table containing the attributes of the tag
local function parseTag(self, s)
local tag_name = string.gsub(s, self._TAG, '%1')
if self.options.subHyphens then
tag_name = string.gsub(tag_name, '-', '_')
end
local tag = {
name = string.gsub(s, self._TAG, '%1'),
name = tag_name,
attrs = {}
}

Expand Down
2 changes: 2 additions & 0 deletions xml2lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function xml2lua.parser(handler)
local options = {
--Indicates if whitespaces should be striped or not
stripWS = 1,
--Should we replace hyphens with underscores in tag names as we parse
subHyphens = 0,
expandEntities = 1,
errorHandler = function(errMsg, pos)
error(string.format("%s [char=%d]\n", errMsg or "Parse Error", pos))
Expand Down