node-xml2js icon indicating copy to clipboard operation
node-xml2js copied to clipboard

Support allowEmpty xmlbuilder in renderOpts

Open k-dahl opened this issue 9 years ago • 2 comments

xml2js seems to pass through everything but the allowEmpty to the render options of xmlbuilder.

var xmlString = root.end({ 
  pretty: true,
  indent: '  ',
  newline: '\n',
  allowEmpty: false
});

...in our specific case we needed to control the allowEmpty parameter, as we have a system that takes in XML that does not allow for self-closing tags, but requires all elements to be submitted even when empty.

Seems like it would be a very easy fix, but I have no experience with CoffeeScript.

k-dahl avatar Jul 19 '17 14:07 k-dahl

Also would love to have this functionality!

CalmKensei avatar Aug 15 '17 21:08 CalmKensei

Passing in your own value for renderOpts when creating the xml2js.Builder works.

const builder = new xml2js.Builder({renderOpts: { 'pretty': true, 'indent': ' ', 'newline': '\n', allowEmpty: true }});

The docs don't mention this and it isn't listed as a default value in defaults.coffee, but as it passes renderOpts straight into .end() you're free to use whichever options are available in xmlbuilder at your resolved version.

Mentioned as spacebeforeslash was only added in v9.0.2 and xml2js only requires ~9.0.1.

josh-green avatar Oct 19 '17 01:10 josh-green