Permalink
Browse files

Adding option to normalize tags

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 048f20b78b4185adb2d4cd5a909e061a3ee882cd
Showing with 6 additions and 1 deletion.
  1. +6 −1 src/xml2js.coffee
View
@@ -11,6 +11,8 @@ exports.defaults =
trim: true
# normalize implicates trimming, just so you know
normalize: true
# normalize tag names to lower case
normalizeTags: false
# set default attribute object key
attrkey: "@"
# set default char object key
@@ -78,7 +80,7 @@ class exports.Parser extends events.EventEmitter
# aliases, so we don't have to type so much
attrkey = @options.attrkey
charkey = @options.charkey
@saxParser.onopentag = (node) =>
obj = {}
obj[charkey] = ""
@@ -99,6 +101,9 @@ class exports.Parser extends events.EventEmitter
obj = stack.pop()
nodeName = obj["#name"]
delete obj["#name"]
if @options.normalizeTags
nodeName = nodeName.toLowerCase()
s = stack[stack.length - 1]
# remove the '#' key altogether if it's blank

0 comments on commit 048f20b

Please sign in to comment.