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 = {
8585Default values:
8686``` javascript
8787var options = {
88- sanitize: false
88+ sanitize: false ,
89+ ignoreNull: false
8990};
9091```
9192
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
9395
9496
9597(* ) 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) {
2121}
2222
2323ToXml . prototype . parse = function ( obj ) {
24+ if ( ! obj ) return ;
25+
2426 var self = this ;
2527 var keys = Object . keys ( obj ) ;
2628 var len = keys . length ;
@@ -60,7 +62,7 @@ ToXml.prototype.parse = function(obj) {
6062 self . closeTag ( key ) ;
6163 }
6264 }
63- } else if ( typeof ( obj [ key ] ) == 'object' ) {
65+ } else if ( typeof ( obj [ key ] ) == 'object' && ! ( self . options . ignoreNull && obj [ key ] === null ) ) {
6466 self . openTag ( key ) ;
6567 self . parse ( obj [ key ] ) ;
6668 self . closeTag ( key ) ;
@@ -97,7 +99,8 @@ ToXml.prototype.completeTag = function() {
9799}
98100function ToXml ( options ) {
99101 var defaultOpts = {
100- sanitize : false
102+ sanitize : false ,
103+ ignoreNull : false
101104 } ;
102105
103106 if ( options ) {
You can’t perform that action at this time.
0 commit comments