davidcalhoun / jstoxml

JavaScript object to XML converter (useful for RSS, podcasts, GPX, AMP, etc)
MIT License
178 stars 23 forks source link

0-depth issues #48

Closed davidcalhoun closed 3 years ago

davidcalhoun commented 3 years ago

There's some bugs in the code related to code at 0 depth outputting unexpected results, e.g.

const table = [
  {
    row: 'bar'
  },
  {
    row: 'bar2'
  }
];
const xmlOptions = {
  header: '<?xml version="1.0" encoding="UTF-16" standalone="yes"?>',
  indent: ' '
};

console.log(toXML(table, xmlOptions));

Outputs this:

<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<row>bar</row>
<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<row>bar2</row>

When it should output this:

<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<row>bar</row>
<row>bar2</row>

Reference: https://stackoverflow.com/questions/68130732/cant-add-header-info-properly-using-jstoxml