Skip to content

Commit

Permalink
Merge pull request #370 from flexi-xu/master
Browse files Browse the repository at this point in the history
Fix issue #119.
  • Loading branch information
Leonidas-from-XIV committed Mar 28, 2017
2 parents 6821d3d + 6852241 commit af83e31
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/builder.js

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

5 changes: 5 additions & 0 deletions src/builder.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class exports.Builder
element.raw wrapCDATA obj
else
element.txt obj
else if Array.isArray obj
# fix issue #119
for own index, child of obj
for key, entry of child
element = render(element.ele(key), entry).up()
else
for own key, child of obj
# Case #1 Attribute
Expand Down
16 changes: 16 additions & 0 deletions test/builder.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,19 @@ module.exports =
actual = builder.buildObject obj
diffeq expected, actual
test.finish()

'test building obj with array': (test) ->
expected = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<MsgId>10</MsgId>
<MsgId2>12</MsgId2>
</root>
"""
opts = cdata: true
builder = new xml2js.Builder opts
obj = [{"MsgId": 10}, {"MsgId2": 12}]
actual = builder.buildObject obj
diffeq expected, actual
test.finish()

0 comments on commit af83e31

Please sign in to comment.