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..3261650 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..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 = {}) { @@ -74,6 +76,15 @@ const XMLMarshaller = class { this.isNsDumped = true } + + if (data [XSI_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 [XSI_TYPE], targetNamespace)) + } this.appendAttributes (node, data) @@ -98,6 +109,11 @@ const XMLMarshaller = class { const {attributes: {type}, children} = node + if (data [XSI_TYPE]) { + let d = {}; for (let k in data) d [k] = data [k] + this.appendElementBody (this.schema.get (data [XSI_TYPE]), d) + } + if (type) return this.appendContent (this.xs.getType (type), data) for (const i of children) this.appendContent (i, data) @@ -111,7 +127,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':