node-xml2js
node-xml2js copied to clipboard
how can we handle xsi:nil ?
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
?
any solution for this?
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