xml-toolkit 1.0.2 → 1.0.5
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 +36 -10
- package/lib/XMLSchema.js +1 -0
- package/package.json +1 -1
- package/test/20040.wsdl +1812 -0
- package/test/sign.xsd +71 -0
- package/test/test.js +61 -0
package/lib/XMLMarshaller.js
CHANGED
|
@@ -37,11 +37,29 @@ const XMLMarshaller = class {
|
|
|
37
37
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
stringify (content) {
|
|
40
|
+
stringify (content, name) {
|
|
41
41
|
|
|
42
|
-
const qName = this.ns.QName (this.schemaElement.name, this.schema.targetNamespace)
|
|
42
|
+
const qName = this.ns.QName (name || this.schemaElement.name, this.schema.targetNamespace)
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
let {complexType, sequence, choice, all, type} = this.schemaElement, group = sequence || choice || all
|
|
45
|
+
|
|
46
|
+
if (type) {
|
|
47
|
+
|
|
48
|
+
type = this.xs.getByReference (type)
|
|
49
|
+
|
|
50
|
+
switch (type._type) {
|
|
51
|
+
|
|
52
|
+
case 'complexType':
|
|
53
|
+
complexType = type
|
|
54
|
+
break
|
|
55
|
+
|
|
56
|
+
case 'simpleType':
|
|
57
|
+
simpleType = type
|
|
58
|
+
break
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
45
63
|
|
|
46
64
|
let buf = ['<' + qName]
|
|
47
65
|
|
|
@@ -50,8 +68,9 @@ const XMLMarshaller = class {
|
|
|
50
68
|
if (complexType) this._aComplexType (buf, complexType, content)
|
|
51
69
|
|
|
52
70
|
buf [0] += '>'
|
|
53
|
-
|
|
71
|
+
|
|
54
72
|
if (complexType) this._bComplexType (buf, complexType, content)
|
|
73
|
+
if (group) this._bSequence (buf, group, content)
|
|
55
74
|
|
|
56
75
|
return buf [0] + '</' + qName + '>'
|
|
57
76
|
|
|
@@ -163,7 +182,7 @@ const XMLMarshaller = class {
|
|
|
163
182
|
}
|
|
164
183
|
|
|
165
184
|
to_string (v, type, restriction = {}) {
|
|
166
|
-
|
|
185
|
+
|
|
167
186
|
const carp = () => {throw new Error (`Invalid value for ${type} type: ${v} (${typeof v})`)}
|
|
168
187
|
|
|
169
188
|
switch (type) {
|
|
@@ -192,6 +211,7 @@ const XMLMarshaller = class {
|
|
|
192
211
|
case 'dateTime':
|
|
193
212
|
switch (typeof v) {
|
|
194
213
|
case 'string':
|
|
214
|
+
if (v.length === 10) return v + 'T00:00:00'
|
|
195
215
|
return v
|
|
196
216
|
case 'number':
|
|
197
217
|
case 'bigint':
|
|
@@ -286,16 +306,22 @@ const XMLMarshaller = class {
|
|
|
286
306
|
}
|
|
287
307
|
|
|
288
308
|
_bSequence (buf, _sequence, content) {
|
|
289
|
-
|
|
309
|
+
|
|
290
310
|
const {element, sequence, choice, all} = _sequence, group = sequence || choice || all
|
|
291
311
|
|
|
292
312
|
if (group) this._bSequence (buf, group, content)
|
|
293
313
|
|
|
294
314
|
if (element) {
|
|
295
|
-
|
|
296
|
-
for (
|
|
297
|
-
|
|
298
|
-
|
|
315
|
+
|
|
316
|
+
for (let e of Array.isArray (element) ? element : [element]) {
|
|
317
|
+
|
|
318
|
+
const {ref} = e; if (ref) e = this.xs.getByReference (ref)
|
|
319
|
+
|
|
320
|
+
const c = content [e.name]
|
|
321
|
+
|
|
322
|
+
this._bElement (buf, e, c)
|
|
323
|
+
|
|
324
|
+
}
|
|
299
325
|
|
|
300
326
|
}
|
|
301
327
|
|
package/lib/XMLSchema.js
CHANGED