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 diff --git a/xml2json.js b/xml2json.js index 481e6d7..d281ca0 100644 --- a/xml2json.js +++ b/xml2json.js @@ -276,15 +276,15 @@ delete result["#cdata-section_asArray"]; } - if( result.__cnt == 0 && config.emptyNodeForm=="text" ) { + if( result.__cnt == 0 && config.emptyNodeForm=="text" && !config.alwaysObjects) { result = ''; } else - if( result.__cnt == 1 && result.__text!=null ) { + if( result.__cnt == 1 && result.__text!=null && !config.alwaysObjects ) { 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 @@ -582,4 +582,4 @@ return VERSION; }; } -})) \ No newline at end of file +}))