node-xml icon indicating copy to clipboard operation
node-xml copied to clipboard

Self-closing tag

Open Griha3212 opened this issue 4 years ago • 1 comments

Hello! Thx for your package! Could you please tell, how I could create such tag SOAP-ENV:Header/

I tried { 'SOAP-ENV:Header': [] },but it becomes SOAP-ENV:Header </SOAP-ENV:Header> Not self-closing tag

Griha3212 avatar Jun 15 '20 10:06 Griha3212

Hi, i think you mean something like this:

xml({
  'myTag': [],
})

this will build into

<myTag></myTag>

i assume you want it to result in <myTag/>?

i have had the same issue and found that if you set the value of your tag to null. it will close it's own tag (eg: xml({ myTag: null }))

this is a neat feature, but it doesn't seem work when dealing with _attr. for example:

xml({
  myTag: [
    { _attr: { myAttrib: "myVal" } }
  ]
})

will result in <myTag myAttrib="myVal"></myTag>

i hope this helps. and i hope this feature could be added with maybe a closeEmptyElement option.

Natejoestev avatar May 25 '23 01:05 Natejoestev