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

too strict attributes validation #5

Open
rlidwka opened this issue Nov 13, 2012 · 1 comment
Open

too strict attributes validation #5

rlidwka opened this issue Nov 13, 2012 · 1 comment

Comments

@rlidwka
Copy link

rlidwka commented Nov 13, 2012

Right now this module expect attributes to be string primitives.

I'd expect numbers to be automatically converted to strings if necessary. There is also a common practice how to handle boolean and non-existent attributes (see below).

// this fails, expected: <element test="123">
xml.startElement('element').writeAttribute('test', 123)

// this fails, expected: <element test="123">
xml.startElement('element').writeAttribute('test', new String('123'))

// this fails, expected: <element test="test">
xml.startElement('element').writeAttribute('test', true)

// this fails, expected: <element>
xml.startElement('element').writeAttribute('test', false)

// this fails, expected: <element>
xml.startElement('element').writeAttribute('test', null)

// this fails, expected: <element>
xml.startElement('element').writeAttribute('test', undefined)
@touv
Copy link
Collaborator

touv commented Nov 14, 2012

There are a small function to check the type of all parameters. cf. https://github.com/lindory-project/node-xml-writer/blob/master/lib/xml-writer.js#L2

This function can be improve. Any pull request are welcome.

chipincode pushed a commit to chipincode/node-xml-writer that referenced this issue Sep 16, 2014
added support for using numeric values in attributes and element text
added support for suppressing attribute if the value is false-y

xw.startElement('tag')
.writeAttribute('key1', false)
.writeAttribute('key2', null)
.writeAttribute('key3', undefined)
.text(3.14)
.endElement();

results in: <tag>3.14</tag>

(see Inist-CNRS#5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants