nashwaan / xml-js

Converter utility between XML text and Javascript object / JSON text.
MIT License
1.29k stars 181 forks source link

add a new option for `simpleAttributes` #195

Open 1mike12 opened 2 years ago

1mike12 commented 2 years ago

where attributes are directly added as keys to the element object instead of being placed into a separate _attributes object

this makes it much easier to work with xml that don't have text inbetween the tags and instead keeps all its info in single <element />.

It's really annoying to work with the _attributes object constantly if your XML shape is anything like the following:

<parent attr1="one" attr2="two">
   <child k1="1" k2="2" ... kn="n" />
   <child k1="1" k2="2" ... kn="n" />
   ...
</parent>

before

{
  parent: {
  __attributes: {attr1: "one", attr2: "two"},
  child: [{__attributes: {k1: "1", k2:"2", kn: "n"} }]
  }
 }

after

{
  parent: {
  attr1: "one", 
  attr2: "two"
  child: [{k1: "1", k2:"2", kn: "n"}]
  }
 }