Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.87k stars 601 forks source link

Improve error if root tag contains invalid character #555

Open Christilut opened 4 years ago

Christilut commented 4 years ago

Took me a while to figure this error out: Error: Invalid character in name which comes from the XmlBuilder.

Turns out this came from the fact that I accidentally did something like this:

builder.buildObject({ 
  $: {
    foo: 'bar'
  },
   ...
}

And the $ is assumed to be the attrKey but gives the above error when used on the root node.

I thought there was something wrong with the attrKey setting or some other bug.

So maybe a quick check can be added with a better error message so others don't fall into this.