Skip to content
This repository was archived by the owner on Jan 7, 2021. It is now read-only.

Commit 69a937d

Browse files
committed
fix issue #37
if coerce is true, xml2json will parse the attributes value from string to number or boolean. So, when convert json to xml, we need test the value type for string, number and boolean.
1 parent 321b134 commit 69a937d

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

lib/json2xml.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module.exports = function toXml(json, xml) {
2121
// First pass, extract strings only
2222
for (var i = 0; i < len; i++) {
2323
var key = keys[i], value = obj[key], isArray = Array.isArray(value);
24-
if (typeof(obj[key]) == 'string' || isArray) {
24+
var type = typeof(value);
25+
if (type == 'string' || type == 'number' || type == 'boolean' || isArray) {
2526
var it = isArray ? value : [value];
2627

2728
it.forEach(function(subVal) {

0 commit comments

Comments
 (0)