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

how can we handle xsi:nil ?

Open sibelius opened this issue 4 years ago • 1 comments

I have an xml with this value on it

<erroExecucao
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:nil="true"
        />

the returned json is like this:

erroExecucao: [
                      {
                        '$': {
                          'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
                          'xsi:nil': 'true'
                        }
                      }
                    ]

how can I transform this into null?

sibelius avatar Apr 24 '20 12:04 sibelius

any solution for this?

thalysonalexr avatar Apr 19 '22 20:04 thalysonalexr

Set the ignoreAttrs parser option to true. Something like:

import { parseStringPromise } from 'xml2js';

...
const rawXml = /* ... your raw XML */
const parsed = await parseStringPromise(rawXml, {
  ignoreAttrs: true,
  explicitArray: false,
});

Available parser options are documented here: https://www.npmjs.com/package/xml2js#options

rsolomon avatar Feb 07 '24 18:02 rsolomon