Skip to content

Commit

Permalink
Added original comments and fixing one bug at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonidas-from-XIV committed Jun 10, 2011
1 parent 72e8fdc commit 69e7405
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 2 additions & 7 deletions lib/xml2js.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/xml2js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ events = require("events")

Parser = ->
that = this
# make the sax parser
@saxParser = sax.parser(true)
# always use the '#' key, even if there are no subkeys
@EXPLICIT_CHARKEY = false
@resultObject = null
stack = []
Expand All @@ -16,6 +18,7 @@ Parser = ->
obj["@"] = {}
obj["@"][key] = node.attributes[key]

# need a place to store the node name
obj["#name"] = node.name
stack.push obj

Expand All @@ -25,12 +28,17 @@ Parser = ->
delete obj["#name"]

s = stack[stack.length - 1]
# remove the '#' key altogether if it's blank
if obj["#"].match(/^\s*$/)
delete obj["#"]
else
# turn 2 or more spaces into one space
obj["#"] = obj["#"].replace(/\s{2,}/g, " ").trim()
if Object.keys(obj).length == 1 and "#" in obj and not (that.EXPLICIT_CHARKEY)
# also do away with '#' key altogether, if there's no subkeys
# unless EXPLICIT_CHARKEY is set
if Object.keys(obj).length == 1 and "#" of obj and not that.EXPLICIT_CHARKEY
obj = obj["#"]

if stack.length > 0
if typeof s[nodeName] == "undefined"
s[nodeName] = obj
Expand Down

0 comments on commit 69e7405

Please sign in to comment.