From 193071d62050f82105946b03c12be431c357f645 Mon Sep 17 00:00:00 2001 From: Roman Matveev Date: Mon, 7 Jul 2025 16:51:41 +0300 Subject: [PATCH 1/2] add xsi:type --- __data__/20319.wsdl | 709 +++++++++++++++++++++++++++++++++++++ __tests__/XMLMarshaller.js | 41 +++ lib/XMLMarshaller.js | 16 +- 3 files changed, 765 insertions(+), 1 deletion(-) create mode 100644 __data__/20319.wsdl diff --git a/__data__/20319.wsdl b/__data__/20319.wsdl new file mode 100644 index 0000000..a40fe20 --- /dev/null +++ b/__data__/20319.wsdl @@ -0,0 +1,709 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/__tests__/XMLMarshaller.js b/__tests__/XMLMarshaller.js index 0977cf5..01123fd 100644 --- a/__tests__/XMLMarshaller.js +++ b/__tests__/XMLMarshaller.js @@ -245,6 +245,47 @@ test ('20040', async () => { }) +test ('20319', async () => { + + const xsdPath = Path.join (__dirname, '..', '__data__', '20319.wsdl') + + const xs = new XMLSchemata (xsdPath) + + const data = { + getOrganizationsByEasRequestWrap: { + Message: { + TestMsg: "Тестовый запроc", + Sender: { + Code: "001801781", + Name: "КИС СПб", + }, + Recipient: { + Code: "ESZHKU001", + Name: "АС ЕС ЖКУ", + }, + ServiceName: "MOService", + TypeCode: "GFNC", + Status: "REQUEST", + Date: "2025-07-07", + ExchangeType: "2" + }, + MessageData: { + AppData: { + data: { + [Symbol.for ('type')]: 'GetOrganizationsByEasRequest', + eas: 123456, + countRecord: 1, + page: 1 + } + } + } + } + } + + expect (xs.stringify (data)).toMatch ('eas>123456<') + +}) + test ('nillable', () => { const xs = getXSSync (Path.join (__dirname, '..', '__data__', 'F9ASyncService_1.xsd')) diff --git a/lib/XMLMarshaller.js b/lib/XMLMarshaller.js index fa7166e..87f4278 100644 --- a/lib/XMLMarshaller.js +++ b/lib/XMLMarshaller.js @@ -74,6 +74,15 @@ const XMLMarshaller = class { this.isNsDumped = true } + + if (data [Symbol.for ('type')]) { + + let {targetNamespace} = this.xs.getSchemaByLocalName(data [Symbol.for ('type')]) + + this.printer + .writeAttribute ('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') + .writeAttribute ('xsi:type', this.ns.QName (data [Symbol.for ('type')], targetNamespace)) + } this.appendAttributes (node, data) @@ -98,6 +107,11 @@ const XMLMarshaller = class { const {attributes: {type}, children} = node + if (data [Symbol.for ('type')]) { + let d = {}; for (let k in data) d [k] = data [k] + this.appendElementBody (this.schema.get ('getOrganizationsByEasRequest'), d) + } + if (type) return this.appendContent (this.xs.getType (type), data) for (const i of children) this.appendContent (i, data) @@ -111,7 +125,7 @@ const XMLMarshaller = class { if (ref) return this.appendAttributes (this.xs.getByReference (ref), data) const {type} = node.attributes; if (type) this.appendAttributes (this.xs.getType (type), data) - + switch (localName) { case 'sequence': From ceba56f49a8161f0ab90d67a17931687a1ce7119 Mon Sep 17 00:00:00 2001 From: Roman Matveev Date: Mon, 7 Jul 2025 17:15:49 +0300 Subject: [PATCH 2/2] xsi_type --- __tests__/XMLMarshaller.js | 2 +- lib/XMLMarshaller.js | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/__tests__/XMLMarshaller.js b/__tests__/XMLMarshaller.js index 01123fd..3261650 100644 --- a/__tests__/XMLMarshaller.js +++ b/__tests__/XMLMarshaller.js @@ -272,7 +272,7 @@ test ('20319', async () => { MessageData: { AppData: { data: { - [Symbol.for ('type')]: 'GetOrganizationsByEasRequest', + [Symbol.for ('type')]: 'getOrganizationsByEasRequest', eas: 123456, countRecord: 1, page: 1 diff --git a/lib/XMLMarshaller.js b/lib/XMLMarshaller.js index 87f4278..1591d35 100644 --- a/lib/XMLMarshaller.js +++ b/lib/XMLMarshaller.js @@ -2,6 +2,8 @@ const assert = require ('assert') const NamespacePrefixesMap = require ('./NamespacePrefixesMap.js') const XMLPrinter = require ('./XMLPrinter.js') +const XSI_TYPE = Symbol.for ('type') + const XMLMarshaller = class { constructor (xs, localName, namespaceURI, printerOptions = {}) { @@ -75,13 +77,13 @@ const XMLMarshaller = class { } - if (data [Symbol.for ('type')]) { + if (data [XSI_TYPE]) { - let {targetNamespace} = this.xs.getSchemaByLocalName(data [Symbol.for ('type')]) + let {targetNamespace} = this.xs.getSchemaByLocalName(data [XSI_TYPE]) this.printer .writeAttribute ('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') - .writeAttribute ('xsi:type', this.ns.QName (data [Symbol.for ('type')], targetNamespace)) + .writeAttribute ('xsi:type', this.ns.QName (data [XSI_TYPE], targetNamespace)) } this.appendAttributes (node, data) @@ -107,9 +109,9 @@ const XMLMarshaller = class { const {attributes: {type}, children} = node - if (data [Symbol.for ('type')]) { + if (data [XSI_TYPE]) { let d = {}; for (let k in data) d [k] = data [k] - this.appendElementBody (this.schema.get ('getOrganizationsByEasRequest'), d) + this.appendElementBody (this.schema.get (data [XSI_TYPE]), d) } if (type) return this.appendContent (this.xs.getType (type), data)