Inist-CNRS / node-xml-writer

Javascript implementation of the classic XMLWriter class
Other
61 stars 28 forks source link

Fail to insert an empty string attribute #18

Open foxever opened 9 years ago

foxever commented 9 years ago

isFalse('') returns true do nothing, testing with Node.js 0.10.40.

function isFalse(s) {
  return typeof s !== 'number' && !s;
}

writeAttribute : function (name, content) {
    if (typeof content == 'function') {
      content = content();
    }
    if (isFalse(content)) {
       return this;
    }
    return this.startAttribute(name).text(content).endAttribute();
}
vijaybhas commented 8 years ago

i am also having the similar issue: we can modify it as

writeAttribute : function (name, content) {
    if (typeof content == 'function') {
      content = content();
    }    
    return this.startAttribute(name).text(content).endAttribute();
}

or it can configurable whether to write empty string or not adding the attribute. perhaps we might need empty string for schema validation.