From d4c0ee05c8423f06ba1721967392c4353aa977d2 Mon Sep 17 00:00:00 2001 From: Alessandro Giansanti Date: Tue, 1 Mar 2016 12:34:20 +0100 Subject: [PATCH 1/4] Update xml2json.js --- xml2json.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xml2json.js b/xml2json.js index 481e6d7..df156a6 100644 --- a/xml2json.js +++ b/xml2json.js @@ -280,7 +280,7 @@ result = ''; } else - if( result.__cnt == 1 && result.__text!=null ) { + if( result.__cnt == 1 && result.__text!=null && !config.alwaysObjects ) { result = result.__text; } else @@ -582,4 +582,4 @@ return VERSION; }; } -})) \ No newline at end of file +})) From 79ab70459ee79b977ea3544df9a4459edfa46984 Mon Sep 17 00:00:00 2001 From: Alessandro Giansanti Date: Tue, 1 Mar 2016 12:46:20 +0100 Subject: [PATCH 2/4] Update README.md doc for config.alwaysObject --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3fe3253..a6c1602 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ The library is very small and has no any dependencies. * `xmlElementsFilter : []` - Filter incoming XML elements. You can pass a stringified path (like 'parent.child1.child2'), regexp or function * `jsonPropertiesFilter : []` - Filter JSON properties for output XML. You can pass a stringified path (like 'parent.child1.child2'), regexp or function * `keepCData : true|false` - If this property defined as false and an XML element has only CData node it will be converted to text without additional property "__cdata". Default is false. + * `alwaysObjects : true|false` - If this property defined as true and an XML element is always parsed as Object indipendently of presence of attributes. Default is false. ## Online demo From 175af21ccc3bdb0d7f60d481d5a6eb777e1f8dff Mon Sep 17 00:00:00 2001 From: Alessandro Giansanti Date: Tue, 1 Mar 2016 12:50:39 +0100 Subject: [PATCH 3/4] Update xml2json.js forgot the cdata case ! --- xml2json.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml2json.js b/xml2json.js index df156a6..9d92641 100644 --- a/xml2json.js +++ b/xml2json.js @@ -284,7 +284,7 @@ result = result.__text; } else - if( result.__cnt == 1 && result.__cdata!=null && !config.keepCData ) { + if( result.__cnt == 1 && result.__cdata!=null && !config.keepCData && !config.alwaysObjects ) { result = result.__cdata; } else From eb80b6c0090315297ca872918cc7132e844f3edf Mon Sep 17 00:00:00 2001 From: Alessandro Giansanti Date: Tue, 1 Mar 2016 13:10:35 +0100 Subject: [PATCH 4/4] Update xml2json.js missed case config.emptyNodeForm=="text" --- xml2json.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml2json.js b/xml2json.js index 9d92641..d281ca0 100644 --- a/xml2json.js +++ b/xml2json.js @@ -276,7 +276,7 @@ delete result["#cdata-section_asArray"]; } - if( result.__cnt == 0 && config.emptyNodeForm=="text" ) { + if( result.__cnt == 0 && config.emptyNodeForm=="text" && !config.alwaysObjects) { result = ''; } else