xml-toolkit 1.0.29 → 1.0.30
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/index.js +11 -1
- package/lib/NamespacePrefixesMap.js +15 -2
- package/lib/NamespacesMap.js +17 -1
- package/lib/SOAP12.js +2 -2
- package/lib/SOAPFault.js +2 -0
- package/lib/XMLMarshaller.js +17 -7
- package/lib/XMLSchemata.js +17 -3
- package/package.json +1 -1
- package/test/test.js +20 -11
package/index.js
CHANGED
|
@@ -14,4 +14,14 @@ for (const name of [
|
|
|
14
14
|
'XMLParser',
|
|
15
15
|
'SOAPFault',
|
|
16
16
|
|
|
17
|
-
]) module.exports [name] = require ('./lib/' + name)
|
|
17
|
+
]) module.exports [name] = require ('./lib/' + name)
|
|
18
|
+
|
|
19
|
+
module.exports.SOAP = v => {switch (String (v)) {
|
|
20
|
+
|
|
21
|
+
case '1.1': return module.exports.SOAP11
|
|
22
|
+
|
|
23
|
+
case '1.2': return module.exports.SOAP12
|
|
24
|
+
|
|
25
|
+
default: throw new Error ('Unknown SOAP version: ' + v)
|
|
26
|
+
|
|
27
|
+
}}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
const assert = require ('assert')
|
|
2
|
+
const {
|
|
3
|
+
|
|
4
|
+
XMLNamespace,
|
|
5
|
+
XMLNamespacePrefix,
|
|
6
|
+
XMLSchemaNamespace,
|
|
7
|
+
XMLSchemaNamespacePrefix,
|
|
8
|
+
|
|
9
|
+
} = require ('./NamespacesMap.js')
|
|
10
|
+
|
|
11
|
+
const DEFAULTS = [
|
|
12
|
+
[XMLNamespace, XMLNamespacePrefix],
|
|
13
|
+
[XMLSchemaNamespace, XMLSchemaNamespacePrefix],
|
|
14
|
+
]
|
|
2
15
|
|
|
3
16
|
const NamespacePrefixesMap = class extends Map {
|
|
4
17
|
|
|
5
18
|
constructor (schemata) {
|
|
6
19
|
|
|
7
|
-
super (
|
|
20
|
+
super (DEFAULTS)
|
|
8
21
|
|
|
9
22
|
for (const uri of schemata.keys ())
|
|
10
23
|
|
|
@@ -26,7 +39,7 @@ const NamespacePrefixesMap = class extends Map {
|
|
|
26
39
|
|
|
27
40
|
let s = ''
|
|
28
41
|
|
|
29
|
-
for (let [k, v] of this.entries ()) s += ' xmlns:' + v + '="' + k + '"'
|
|
42
|
+
for (let [k, v] of this.entries ()) if (k !== XMLNamespace) s += ' xmlns:' + v + '="' + k + '"'
|
|
30
43
|
|
|
31
44
|
return s
|
|
32
45
|
|
package/lib/NamespacesMap.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
const XMLNamespace = 'http://www.w3.org/XML/1998/namespace'
|
|
2
|
+
const XMLNamespacePrefix = 'xml'
|
|
3
|
+
|
|
4
|
+
const XMLSchemaNamespace = 'http://www.w3.org/2001/XMLSchema'
|
|
5
|
+
const XMLSchemaNamespacePrefix = 'xsi'
|
|
6
|
+
|
|
7
|
+
const DEFAULTS = [
|
|
8
|
+
[XMLNamespacePrefix, XMLNamespace],
|
|
9
|
+
[XMLSchemaNamespacePrefix, XMLSchemaNamespace],
|
|
10
|
+
]
|
|
11
|
+
|
|
1
12
|
const NamespacesMap = class extends Map {
|
|
2
13
|
|
|
3
14
|
constructor (xmlNode) {
|
|
@@ -6,7 +17,7 @@ const NamespacesMap = class extends Map {
|
|
|
6
17
|
|
|
7
18
|
if (parent === null) {
|
|
8
19
|
|
|
9
|
-
super ()
|
|
20
|
+
super (DEFAULTS)
|
|
10
21
|
|
|
11
22
|
}
|
|
12
23
|
else {
|
|
@@ -45,4 +56,9 @@ const NamespacesMap = class extends Map {
|
|
|
45
56
|
|
|
46
57
|
}
|
|
47
58
|
|
|
59
|
+
NamespacesMap.XMLNamespace = XMLNamespace
|
|
60
|
+
NamespacesMap.XMLNamespacePrefix = XMLNamespacePrefix
|
|
61
|
+
NamespacesMap.XMLSchemaNamespace = XMLSchemaNamespace
|
|
62
|
+
NamespacesMap.XMLSchemaNamespacePrefix = XMLSchemaNamespacePrefix
|
|
63
|
+
|
|
48
64
|
module.exports = NamespacesMap
|
package/lib/SOAP12.js
CHANGED
|
@@ -14,12 +14,12 @@ const get_xs = () => {
|
|
|
14
14
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const _fault_xml = ({code, message, actor, detail}) => {
|
|
17
|
+
const _fault_xml = ({code, message, actor, detail, lang}) => {
|
|
18
18
|
|
|
19
19
|
if (typeof code === 'string') code = {localName: code, namespaceURI: 'http://www.w3.org/2003/05/soap-envelope'}
|
|
20
20
|
|
|
21
21
|
const Fault = {
|
|
22
|
-
Reason: {Text: message},
|
|
22
|
+
Reason: {Text: {lang, null: message}},
|
|
23
23
|
Code: {Value: code},
|
|
24
24
|
Role: actor,
|
|
25
25
|
Detail: detail
|
package/lib/SOAPFault.js
CHANGED
package/lib/XMLMarshaller.js
CHANGED
|
@@ -172,6 +172,8 @@ const XMLMarshaller = class {
|
|
|
172
172
|
|
|
173
173
|
case 'anyAttribute':
|
|
174
174
|
|
|
175
|
+
if (data == null || typeof data !== 'object') return
|
|
176
|
+
|
|
175
177
|
if (null in data)
|
|
176
178
|
|
|
177
179
|
for (const o of Object.values (data [null]))
|
|
@@ -184,6 +186,8 @@ const XMLMarshaller = class {
|
|
|
184
186
|
|
|
185
187
|
case 'attribute':
|
|
186
188
|
|
|
189
|
+
if (data == null || typeof data !== 'object') return
|
|
190
|
+
|
|
187
191
|
if (!(name in data)) return
|
|
188
192
|
|
|
189
193
|
let v = data [name]; if (v == null) return
|
|
@@ -205,10 +209,6 @@ const XMLMarshaller = class {
|
|
|
205
209
|
|
|
206
210
|
break
|
|
207
211
|
|
|
208
|
-
case 'extension':
|
|
209
|
-
|
|
210
|
-
this.appendAttributes (this.xs.getType (attributes.base), data)
|
|
211
|
-
|
|
212
212
|
case 'any':
|
|
213
213
|
case 'sequence':
|
|
214
214
|
case 'choice':
|
|
@@ -217,6 +217,10 @@ const XMLMarshaller = class {
|
|
|
217
217
|
|
|
218
218
|
return
|
|
219
219
|
|
|
220
|
+
case 'extension':
|
|
221
|
+
|
|
222
|
+
this.appendAttributes (this.xs.getType (attributes.base), data)
|
|
223
|
+
|
|
220
224
|
default:
|
|
221
225
|
|
|
222
226
|
for (const i of children) this.appendAttributes (i, data)
|
|
@@ -236,12 +240,18 @@ const XMLMarshaller = class {
|
|
|
236
240
|
switch (localName) {
|
|
237
241
|
|
|
238
242
|
case 'any':
|
|
243
|
+
|
|
239
244
|
if (null in data) for (const xml in data [null]) this.buf += xml
|
|
240
|
-
|
|
245
|
+
|
|
246
|
+
return
|
|
241
247
|
|
|
242
248
|
case 'simpleType':
|
|
243
249
|
|
|
244
|
-
|
|
250
|
+
if (data !== null && typeof data === 'object') data = data [null]
|
|
251
|
+
|
|
252
|
+
if (data != null) this.appendScalar (node, data)
|
|
253
|
+
|
|
254
|
+
return
|
|
245
255
|
|
|
246
256
|
case 'element':
|
|
247
257
|
|
|
@@ -255,7 +265,7 @@ const XMLMarshaller = class {
|
|
|
255
265
|
|
|
256
266
|
for (const d of v) this.appendElement (node, d, qName)
|
|
257
267
|
|
|
258
|
-
|
|
268
|
+
return
|
|
259
269
|
|
|
260
270
|
case 'extension':
|
|
261
271
|
|
package/lib/XMLSchemata.js
CHANGED
|
@@ -8,6 +8,7 @@ const XMLReader = require ('./XMLReader.js')
|
|
|
8
8
|
const XMLNode = require ('./XMLNode.js')
|
|
9
9
|
const XMLSchema = require ('./XMLSchema.js'), {adjustNode} = XMLSchema
|
|
10
10
|
const NamespacePrefixesMap = require ('./NamespacePrefixesMap.js')
|
|
11
|
+
const {XMLNamespace, XMLSchemaNamespace} = require ('./NamespacesMap.js')
|
|
11
12
|
const XMLMarshaller = require ('./XMLMarshaller.js')
|
|
12
13
|
|
|
13
14
|
const IDX = Symbol ('_index')
|
|
@@ -27,7 +28,7 @@ const XMLSchemata = class extends Map {
|
|
|
27
28
|
this.addFileSync (fn)
|
|
28
29
|
delete this.parser
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
register (name, targetNamespace) {
|
|
@@ -53,15 +54,28 @@ const XMLSchemata = class extends Map {
|
|
|
53
54
|
targetNamespace: namespaceURI
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
const s = this.get (namespaceURI); if (s == null) throw new Error ('Unknown namespace: ' + namespaceURI)
|
|
58
|
+
|
|
59
|
+
return s.getType (localName)
|
|
57
60
|
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
getByReference (ref) {
|
|
61
64
|
|
|
62
65
|
const [localName, namespaceURI] = ref
|
|
66
|
+
|
|
67
|
+
if (namespaceURI === XMLNamespace) return {
|
|
68
|
+
localName: 'attribute',
|
|
69
|
+
namespaceURI,
|
|
70
|
+
attributes: {name: localName, type: ['string', XMLSchemaNamespace]},
|
|
71
|
+
children: [],
|
|
72
|
+
namespacesMap: {},
|
|
73
|
+
targetNamespace: namespaceURI
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const s = this.get (namespaceURI); if (s == null) throw new Error ('Unknown namespace: ' + namespaceURI)
|
|
63
77
|
|
|
64
|
-
return
|
|
78
|
+
return s.get (localName)
|
|
65
79
|
|
|
66
80
|
}
|
|
67
81
|
|
package/package.json
CHANGED
package/test/test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fs = require ('fs')
|
|
2
2
|
const assert = require ('assert')
|
|
3
|
-
const {XMLReader, SAXEvent, XMLLexer, AttributesMap, XMLNode, XMLSchemata, SOAP11, SOAP12, EntityResolver, XMLIterator, XMLParser, SOAPFault} = require ('../')
|
|
3
|
+
const {XMLReader, SAXEvent, XMLLexer, AttributesMap, XMLNode, XMLSchemata, SOAP11, SOAP12, EntityResolver, XMLIterator, XMLParser, SOAPFault, SOAP} = require ('../')
|
|
4
4
|
|
|
5
5
|
async function test_001_lexer_sync (fn) {
|
|
6
6
|
|
|
@@ -388,9 +388,18 @@ async function test_009_schemata (fn) {
|
|
|
388
388
|
|
|
389
389
|
const xs = new XMLSchemata ('test/' + fn)
|
|
390
390
|
|
|
391
|
-
console.log (xs)
|
|
391
|
+
// console.log (xs)
|
|
392
|
+
|
|
393
|
+
// console.log (xs.stringify ({AckResponse: null}))
|
|
392
394
|
|
|
393
|
-
|
|
395
|
+
const data = {
|
|
396
|
+
AckRequest: {
|
|
397
|
+
// AckTargetMessage: {Id: 1, accepted: true, null: 2},
|
|
398
|
+
AckTargetMessage: 11111,
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
console.log (xs.stringify (data))
|
|
394
403
|
|
|
395
404
|
}
|
|
396
405
|
|
|
@@ -467,8 +476,8 @@ function test_013_soap () {
|
|
|
467
476
|
detail
|
|
468
477
|
})
|
|
469
478
|
|
|
470
|
-
console.log (
|
|
471
|
-
console.log (
|
|
479
|
+
console.log (SOAP (1.1).message (f))
|
|
480
|
+
console.log (SOAP (1.2).message (f))
|
|
472
481
|
|
|
473
482
|
}
|
|
474
483
|
|
|
@@ -488,13 +497,13 @@ async function main () {
|
|
|
488
497
|
// await test_003_emitter_sync ('ent.xml')
|
|
489
498
|
// await test_003_emitter_sync ('soap.xml')
|
|
490
499
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
500
|
+
await test_004_schemata ()
|
|
501
|
+
await test_005_schemata ()
|
|
502
|
+
await test_006_schemata ()
|
|
494
503
|
test_007_wsdl ()
|
|
495
|
-
|
|
504
|
+
await test_008_schemata ()
|
|
496
505
|
|
|
497
|
-
|
|
506
|
+
test_009_schemata ('smev-message-exchange-service-1.1.xsd')
|
|
498
507
|
// test_009_schemata ('sign.xsd')
|
|
499
508
|
|
|
500
509
|
// test_010_node ()
|
|
@@ -504,7 +513,7 @@ async function main () {
|
|
|
504
513
|
// test_012_parser ('param_types.xml')
|
|
505
514
|
// test_012_parser ('20040.wsdl')
|
|
506
515
|
|
|
507
|
-
|
|
516
|
+
test_013_soap ()
|
|
508
517
|
|
|
509
518
|
}
|
|
510
519
|
|