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

It is giving error while working with keys having : in it

Open shaileshbonzer opened this issue 3 years ago • 1 comments

I am going to send XML response from my node js api.

When I am sending data like following

res.set('Content-Type', 'text/xml');

let example5 = [
  {
    toys: [
      {
        _attr: {
          decade: '80s',
          locale: 'US'
        }
      },
      {
        toy: 'Transformers'
      },
      {
        toy: [
          {
            _attr: {
              knowing: 'half the battle'
            }
          },
          'GI Joe'
        ]
      },
      {
        toy: [
          {
            name: 'He-man'
          },
          {
            'g:brand': 'He-man'
          },
          {
            description: {
              _cdata: '<strong>Master of the Universe!</strong>'
            }
          }
        ]
      }
    ]
  }
]

return res.send(xml(example5, true));

When using the key with : it is giving error like this xml_error

shaileshbonzer avatar Feb 28 '22 15:02 shaileshbonzer

In xml the : marks the use of a namspace, you need to declare the namespace if you want the xml document to be valid. You can find a simple example here: https://www.w3schools.com/xml/xml_namespaces.asp

EECOLOR avatar Jul 14 '23 11:07 EECOLOR