xml-toolkit 1.0.54 → 1.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/XMLMarshaller.js +17 -1
- package/package.json +1 -1
package/lib/XMLMarshaller.js
CHANGED
|
@@ -2,6 +2,8 @@ const assert = require ('assert')
|
|
|
2
2
|
const NamespacePrefixesMap = require ('./NamespacePrefixesMap.js')
|
|
3
3
|
const XMLPrinter = require ('./XMLPrinter.js')
|
|
4
4
|
|
|
5
|
+
const XSI_TYPE = Symbol.for ('type')
|
|
6
|
+
|
|
5
7
|
const XMLMarshaller = class {
|
|
6
8
|
|
|
7
9
|
constructor (xs, localName, namespaceURI, printerOptions = {}) {
|
|
@@ -74,6 +76,15 @@ const XMLMarshaller = class {
|
|
|
74
76
|
this.isNsDumped = true
|
|
75
77
|
|
|
76
78
|
}
|
|
79
|
+
|
|
80
|
+
if (data [XSI_TYPE]) {
|
|
81
|
+
|
|
82
|
+
let {targetNamespace} = this.xs.getSchemaByLocalName(data [XSI_TYPE])
|
|
83
|
+
|
|
84
|
+
this.printer
|
|
85
|
+
.writeAttribute ('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance')
|
|
86
|
+
.writeAttribute ('xsi:type', this.ns.QName (data [XSI_TYPE], targetNamespace))
|
|
87
|
+
}
|
|
77
88
|
|
|
78
89
|
this.appendAttributes (node, data)
|
|
79
90
|
|
|
@@ -98,6 +109,11 @@ const XMLMarshaller = class {
|
|
|
98
109
|
|
|
99
110
|
const {attributes: {type}, children} = node
|
|
100
111
|
|
|
112
|
+
if (data [XSI_TYPE]) {
|
|
113
|
+
let d = {}; for (let k in data) d [k] = data [k]
|
|
114
|
+
this.appendContent (this.schema.getType (data [XSI_TYPE]), d)
|
|
115
|
+
}
|
|
116
|
+
|
|
101
117
|
if (type) return this.appendContent (this.xs.getType (type), data)
|
|
102
118
|
|
|
103
119
|
for (const i of children) this.appendContent (i, data)
|
|
@@ -111,7 +127,7 @@ const XMLMarshaller = class {
|
|
|
111
127
|
if (ref) return this.appendAttributes (this.xs.getByReference (ref), data)
|
|
112
128
|
|
|
113
129
|
const {type} = node.attributes; if (type) this.appendAttributes (this.xs.getType (type), data)
|
|
114
|
-
|
|
130
|
+
|
|
115
131
|
switch (localName) {
|
|
116
132
|
|
|
117
133
|
case 'sequence':
|