Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boolean and non-existent attributes #26

Closed
rlidwka opened this issue Nov 14, 2012 · 1 comment
Closed

boolean and non-existent attributes #26

rlidwka opened this issue Nov 14, 2012 · 1 comment
Labels

Comments

@rlidwka
Copy link

rlidwka commented Nov 14, 2012

Right now if I pass undefined object as a value, it would output "undefined" string. And to exclude such attributes I would need to filter out the entire attributes object before passing it to xmlbuilder.

Consider this example:

/*
 *  Configuration
 */
var param1 = 123;
// I want to turn off param2, so it doesn't appear in xml. How do I do it here?
var param2;

/*
 *  XML building
 */
var xml = builder.create('root')
  .ele('test', {
    param1: param1,
    param2: param2
  })

Since null and undefined aren't useful anyway, I suggest to exclude them from attributes in the library itself like this:

// expected: <root><test param1="123" /></root>
var xml = builder.create('root').ele('test', { param1: 123, param2: null })

// expected: <root><test param1="123" /></root>
var xml = builder.create('root').ele('test', { param1: 123, param2: undefined })

The same thing is about boolean attributes. If someone pass false, it's unlikely that he wants to get "false" string instead of it. So, I'd like to see this:

// expected: <root><test param1="123" param2="param2" /></root>
var xml = builder.create('root').ele('test', { param1: 123, param2: true })

// expected: <root><test param1="123" /></root>
var xml = builder.create('root').ele('test', { param1: 123, param2: false })
@oozcitak
Copy link
Owner

Hello and sorry for the late response. I am thinking of adding a flag to control the behavior of null and undefined attributes. But the default behavior will be to throw an exception on such values. This would be consistent with the rest of the lib.

The true behavior you described above seems like XHTML. Since this is a generic XML generator, I don't think we should support specialized XML dialects out of the box.

Cheers,
Ozgur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants