oozcitak / xmlbuilder-js

An XML builder for node.js
MIT License
919 stars 108 forks source link

Issue with method "attribute" in XMLNode lib #210

Closed dexter1023 closed 5 years ago

dexter1023 commented 5 years ago

Hi, I've got that error while create xml document from object: TypeError: this.attribute is not a function at XMLDocument.element (/node_modules/xmlbuilder/lib/XMLNode.js:131:32) I checked code and there's no implementation of function "attribute".

oozcitak commented 5 years ago

Can you post your code please?

afarah1 commented 1 year ago

For anyone wondering, this happens when you try to add an attribute to the document instead of an element. Example:

builder.create({
  root: {
    child: 'value'
  },
  '@attr': 'value'
});

Uncaught TypeError TypeError: this.attribute is not a function

Instead of

builder.create({
  root: {
    child: 'value',
    '@attr': 'value', // root attr, not childs
  },
});

<root attr="value"><child>value</child></root>