From ef9df53e91e7f54f7d8840ef1a50bf9ba871742b Mon Sep 17 00:00:00 2001 From: Brad Greer <59664356+Lexington120@users.noreply.github.com> Date: Wed, 14 May 2025 20:16:23 -0500 Subject: [PATCH 1/2] nil being mapped to null - attributes still being removed however --- src/wsdl/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wsdl/index.ts b/src/wsdl/index.ts index 2fe42b193..37407c71b 100644 --- a/src/wsdl/index.ts +++ b/src/wsdl/index.ts @@ -359,9 +359,12 @@ export class WSDL { } if (cur.nil === true) { - if (this.options.handleNilAsNull) { + // if (this.options.handleNilAsNull) { + if (true) { obj = null; + console.log('null value handled') } else { + console.log('null value not handled') return; } } From a3e095ea06538162a4c0a4842f64ca8c3919beba Mon Sep 17 00:00:00 2001 From: Brad Greer <59664356+Lexington120@users.noreply.github.com> Date: Thu, 15 May 2025 15:00:45 -0500 Subject: [PATCH 2/2] nil attributes preserved - not recorded elements removed - conversion works as desired --- src/wsdl/index.ts | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/wsdl/index.ts b/src/wsdl/index.ts index 37407c71b..b58e50a67 100644 --- a/src/wsdl/index.ts +++ b/src/wsdl/index.ts @@ -190,6 +190,11 @@ export class WSDL { return saxStream; } + + + + + public xmlToObject(xml, callback?) { const p: any = typeof callback === 'function' ? {} : sax.parser(true, null); let objectName = null; @@ -351,28 +356,32 @@ export class WSDL { const topObject = top.object; const topSchema = top.schema; const name = splitQName(nsName).name; - + if (typeof cur.schema === 'string' && (cur.schema === 'string' || cur.schema.split(':')[1] === 'string')) { if (typeof obj === 'object' && Object.keys(obj).length === 0) { obj = cur.object = (this.options.preserveWhitespace ? cur.text || '' : ''); } } - + + // Handle nil attribute properly while preserving other attributes if (cur.nil === true) { - // if (this.options.handleNilAsNull) { - if (true) { - obj = null; - console.log('null value handled') + // Check for NV == 7701003 attribute and skip handling if match is found + const attributes = obj[this.options.attributesKey]; + if (attributes && attributes.NV === '7701003') { + return; // Skip further processing of this element + } + + // Store null value in the valueKey instead of replacing the entire object + if (attributes) { + // Keep attributes, no other changes } else { - console.log('null value not handled') - return; + // If there are no attributes, set the object to null + obj = null; } - } - - if (_.isPlainObject(obj) && !Object.keys(obj).length) { + } else if (_.isPlainObject(obj) && !Object.keys(obj).length) { obj = null; } - + if (topSchema && topSchema[name + '[]']) { if (!topObject[name]) { topObject[name] = []; @@ -386,7 +395,7 @@ export class WSDL { } else { topObject[name] = obj; } - + if (cur.id) { refs[cur.id].obj = obj; }