Skip to content

Commit

Permalink
Adding option to normalize tags
Browse files Browse the repository at this point in the history
Because javascript is case sensitive tags URL Url and url are all different
This adds a normalizeTags option (off by default) that makes all tag names lowercase
  • Loading branch information
neopunisher committed Oct 7, 2012
1 parent 2c8600d commit 048f20b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/xml2js.coffee
Expand Up @@ -11,6 +11,8 @@ exports.defaults =
trim: true trim: true
# normalize implicates trimming, just so you know # normalize implicates trimming, just so you know
normalize: true normalize: true
# normalize tag names to lower case
normalizeTags: false
# set default attribute object key # set default attribute object key
attrkey: "@" attrkey: "@"
# set default char object key # set default char object key
Expand Down Expand Up @@ -78,7 +80,7 @@ class exports.Parser extends events.EventEmitter
# aliases, so we don't have to type so much # aliases, so we don't have to type so much
attrkey = @options.attrkey attrkey = @options.attrkey
charkey = @options.charkey charkey = @options.charkey

@saxParser.onopentag = (node) => @saxParser.onopentag = (node) =>
obj = {} obj = {}
obj[charkey] = "" obj[charkey] = ""
Expand All @@ -99,6 +101,9 @@ class exports.Parser extends events.EventEmitter
obj = stack.pop() obj = stack.pop()
nodeName = obj["#name"] nodeName = obj["#name"]
delete obj["#name"] delete obj["#name"]

if @options.normalizeTags
nodeName = nodeName.toLowerCase()


s = stack[stack.length - 1] s = stack[stack.length - 1]
# remove the '#' key altogether if it's blank # remove the '#' key altogether if it's blank
Expand Down

0 comments on commit 048f20b

Please sign in to comment.