Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions xml2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -582,4 +582,4 @@
return VERSION;
};
}
}))
}))