Skip to content
Merged
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
16 changes: 16 additions & 0 deletions spec/j2x_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ describe("XMLBuilder", function() {
expect(result).toEqual(expected);
});

it('should parse to XML with empty CDATA', function() {
const jObj = {
a: {
$cdata: null,
},
b: {
$cdata: undefined,
},
};
const builder = new XMLBuilder({ cdataPropName: '$cdata' });
const result = builder.build(jObj);
//console.log(result);
const expected = `<a></a><b></b>`;
expect(result).toEqual(expected);
});

it("should parse to XML with attributes as separate node", function() {
const jObj = {
a: {
Expand Down
2 changes: 2 additions & 0 deletions src/xmlbuilder/json2xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Builder.prototype.j2x = function(jObj, level, ajPath) {
// null attribute should be ignored by the attribute list, but should not cause the tag closing
if (this.isAttribute(key)) {
val += '';
} else if (key === this.options.cdataPropName) {
val += '';
} else if (key[0] === '?') {
val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
} else {
Expand Down
Loading