This repository was archived by the owner on Jan 7, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -85,11 +85,13 @@ var chars = {
85
85
Default values:
86
86
``` javascript
87
87
var options = {
88
- sanitize: false
88
+ sanitize: false ,
89
+ ignoreNull: false
89
90
};
90
91
```
91
92
92
- ` sanitize: false ` is the default option to behave like previous versions
93
+ * ` sanitize: false ` is the default option to behave like previous versions
94
+ * ** ignoreNull:** Ignores all null values
93
95
94
96
95
97
(* ) xml2json tranforms CDATA content to JSON, but it doesn't generate a reversible structure.
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ module.exports = function (json, options) {
21
21
}
22
22
23
23
ToXml . prototype . parse = function ( obj ) {
24
+ if ( ! obj ) return ;
25
+
24
26
var self = this ;
25
27
var keys = Object . keys ( obj ) ;
26
28
var len = keys . length ;
@@ -60,7 +62,7 @@ ToXml.prototype.parse = function(obj) {
60
62
self . closeTag ( key ) ;
61
63
}
62
64
}
63
- } else if ( typeof ( obj [ key ] ) == 'object' ) {
65
+ } else if ( typeof ( obj [ key ] ) == 'object' && ! ( self . options . ignoreNull && obj [ key ] === null ) ) {
64
66
self . openTag ( key ) ;
65
67
self . parse ( obj [ key ] ) ;
66
68
self . closeTag ( key ) ;
@@ -97,7 +99,8 @@ ToXml.prototype.completeTag = function() {
97
99
}
98
100
function ToXml ( options ) {
99
101
var defaultOpts = {
100
- sanitize : false
102
+ sanitize : false ,
103
+ ignoreNull : false
101
104
} ;
102
105
103
106
if ( options ) {
You can’t perform that action at this time.
0 commit comments