xml-toolkit 1.0.23 → 1.0.24
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 +1 -7
- package/lib/XMLSchema.js +27 -11
- package/package.json +1 -1
- package/test/{soap.xsd → soap-1.1.xsd} +0 -0
- package/test/soap-1.2.xsd +166 -0
- package/test/test.js +101 -9
package/lib/XMLMarshaller.js
CHANGED
|
@@ -162,13 +162,7 @@ const XMLMarshaller = class {
|
|
|
162
162
|
|
|
163
163
|
let v = data [name]; if (v == null) return
|
|
164
164
|
|
|
165
|
-
this.buf += ' ' + (
|
|
166
|
-
|
|
167
|
-
this.xs.get (targetNamespace).isAttributeElementFormQualified ? this.ns.QName (name, targetNamespace)
|
|
168
|
-
|
|
169
|
-
: name
|
|
170
|
-
|
|
171
|
-
) + '="'
|
|
165
|
+
this.buf += ' ' + this.ns.QName (name, targetNamespace) + '="'
|
|
172
166
|
|
|
173
167
|
if (type) {
|
|
174
168
|
|
package/lib/XMLSchema.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
const TYPES = Symbol ('_types')
|
|
2
2
|
|
|
3
|
+
const FORM_U = 'unqualified'
|
|
4
|
+
const FORM_Q = 'qualified'
|
|
5
|
+
|
|
3
6
|
const XMLSchema = class extends Map {
|
|
4
7
|
|
|
5
8
|
constructor (parent, targetNamespace) {
|
|
@@ -7,10 +10,10 @@ const XMLSchema = class extends Map {
|
|
|
7
10
|
super ()
|
|
8
11
|
|
|
9
12
|
this.parent = parent
|
|
13
|
+
|
|
10
14
|
this.targetNamespace = targetNamespace
|
|
11
15
|
|
|
12
|
-
this.
|
|
13
|
-
this.isAttributeElementFormQualified = false
|
|
16
|
+
this.formDefault = {}
|
|
14
17
|
|
|
15
18
|
this [TYPES] = new Map ()
|
|
16
19
|
|
|
@@ -21,13 +24,12 @@ const XMLSchema = class extends Map {
|
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
add (node, options = {}) {
|
|
24
|
-
|
|
25
|
-
this.copyTargetNamespace (node)
|
|
26
|
-
|
|
27
|
+
|
|
27
28
|
const {attributes, children} = node
|
|
29
|
+
|
|
30
|
+
for (const name of ['element', 'attribute']) this.formDefault [name] = attributes [name + 'FormDefault'] || FORM_U
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
if (attributes.attributeFormDefault === 'qualified') this.isAttributeElementFormQualified = true
|
|
32
|
+
this.copyTargetNamespace (node)
|
|
31
33
|
|
|
32
34
|
for (const e of children) {
|
|
33
35
|
|
|
@@ -50,13 +52,27 @@ const XMLSchema = class extends Map {
|
|
|
50
52
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
copyTargetNamespace (node) {
|
|
55
|
+
copyTargetNamespace (node, force = false) {
|
|
54
56
|
|
|
55
57
|
if (typeof node !== 'object') return
|
|
58
|
+
|
|
59
|
+
const {localName} = node
|
|
60
|
+
|
|
61
|
+
for (const e of node.children) this.copyTargetNamespace (e, localName === 'schema')
|
|
62
|
+
|
|
63
|
+
if ('targetNamespace' in node) return
|
|
64
|
+
|
|
65
|
+
const {formDefault} = this; if (!(localName in formDefault)) return
|
|
66
|
+
|
|
67
|
+
if (!force) {
|
|
68
|
+
|
|
69
|
+
const {form} = node.attributes
|
|
70
|
+
|
|
71
|
+
if (form !== FORM_Q && formDefault [localName] !== FORM_Q) return
|
|
72
|
+
|
|
73
|
+
}
|
|
56
74
|
|
|
57
|
-
node.targetNamespace = this.targetNamespace
|
|
58
|
-
|
|
59
|
-
for (const e of node.children) this.copyTargetNamespace (e)
|
|
75
|
+
node.targetNamespace = this.targetNamespace
|
|
60
76
|
|
|
61
77
|
}
|
|
62
78
|
|
package/package.json
CHANGED
|
File without changes
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
<!-- Schema defined in the SOAP Version 1.2 Part 1 specification
|
|
2
|
+
Recommendation:
|
|
3
|
+
http://www.w3.org/TR/2003/REC-soap12-part1-20030624/
|
|
4
|
+
$Id: soap-envelope.xsd,v 1.2 2006/12/20 20:43:36 ylafon Exp $
|
|
5
|
+
|
|
6
|
+
Copyright (C)2003 W3C(R) (MIT, ERCIM, Keio), All Rights Reserved.
|
|
7
|
+
W3C viability, trademark, document use and software licensing rules
|
|
8
|
+
apply.
|
|
9
|
+
http://www.w3.org/Consortium/Legal/
|
|
10
|
+
|
|
11
|
+
This document is governed by the W3C Software License [1] as
|
|
12
|
+
described in the FAQ [2].
|
|
13
|
+
|
|
14
|
+
[1] http://www.w3.org/Consortium/Legal/copyright-software-19980720
|
|
15
|
+
[2] http://www.w3.org/Consortium/Legal/IPR-FAQ-20000620.html#DTD
|
|
16
|
+
-->
|
|
17
|
+
|
|
18
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
19
|
+
xmlns:tns="http://www.w3.org/2003/05/soap-envelope"
|
|
20
|
+
targetNamespace="http://www.w3.org/2003/05/soap-envelope"
|
|
21
|
+
elementFormDefault="qualified" >
|
|
22
|
+
<!--
|
|
23
|
+
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
|
|
24
|
+
schemaLocation="http://www.w3.org/2001/xml.xsd"/>
|
|
25
|
+
-->
|
|
26
|
+
|
|
27
|
+
<!-- Envelope, header and body -->
|
|
28
|
+
<xs:element name="Envelope" type="tns:Envelope" />
|
|
29
|
+
<xs:complexType name="Envelope" >
|
|
30
|
+
<xs:sequence>
|
|
31
|
+
<xs:element ref="tns:Header" minOccurs="0" />
|
|
32
|
+
<xs:element ref="tns:Body" minOccurs="1" />
|
|
33
|
+
</xs:sequence>
|
|
34
|
+
<xs:anyAttribute namespace="##other" processContents="lax" />
|
|
35
|
+
</xs:complexType>
|
|
36
|
+
|
|
37
|
+
<xs:element name="Header" type="tns:Header" />
|
|
38
|
+
<xs:complexType name="Header" >
|
|
39
|
+
<xs:annotation>
|
|
40
|
+
<xs:documentation>
|
|
41
|
+
Elements replacing the wildcard MUST be namespace qualified, but can be in the targetNamespace
|
|
42
|
+
</xs:documentation>
|
|
43
|
+
</xs:annotation>
|
|
44
|
+
<xs:sequence>
|
|
45
|
+
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
|
|
46
|
+
</xs:sequence>
|
|
47
|
+
<xs:anyAttribute namespace="##other" processContents="lax" />
|
|
48
|
+
</xs:complexType>
|
|
49
|
+
|
|
50
|
+
<xs:element name="Body" type="tns:Body" />
|
|
51
|
+
<xs:complexType name="Body" >
|
|
52
|
+
<xs:sequence>
|
|
53
|
+
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
|
|
54
|
+
</xs:sequence>
|
|
55
|
+
<xs:anyAttribute namespace="##other" processContents="lax" />
|
|
56
|
+
</xs:complexType>
|
|
57
|
+
|
|
58
|
+
<!-- Global Attributes. The following attributes are intended to be
|
|
59
|
+
usable via qualified attribute names on any complex type referencing
|
|
60
|
+
them. -->
|
|
61
|
+
<xs:attribute name="mustUnderstand" type="xs:boolean" default="0" />
|
|
62
|
+
<xs:attribute name="relay" type="xs:boolean" default="0" />
|
|
63
|
+
<xs:attribute name="role" type="xs:anyURI" />
|
|
64
|
+
|
|
65
|
+
<!-- 'encodingStyle' indicates any canonicalization conventions
|
|
66
|
+
followed in the contents of the containing element. For example, the
|
|
67
|
+
value 'http://www.w3.org/2003/05/soap-encoding' indicates the pattern
|
|
68
|
+
described in the SOAP Version 1.2 Part 2: Adjuncts Recommendation -->
|
|
69
|
+
|
|
70
|
+
<xs:attribute name="encodingStyle" type="xs:anyURI" />
|
|
71
|
+
|
|
72
|
+
<xs:element name="Fault" type="tns:Fault" />
|
|
73
|
+
<xs:complexType name="Fault" final="extension" >
|
|
74
|
+
<xs:annotation>
|
|
75
|
+
<xs:documentation>
|
|
76
|
+
Fault reporting structure
|
|
77
|
+
</xs:documentation>
|
|
78
|
+
</xs:annotation>
|
|
79
|
+
<xs:sequence>
|
|
80
|
+
<xs:element name="Code" type="tns:faultcode" />
|
|
81
|
+
<xs:element name="Reason" type="tns:faultreason" />
|
|
82
|
+
<xs:element name="Node" type="xs:anyURI" minOccurs="0" />
|
|
83
|
+
<xs:element name="Role" type="xs:anyURI" minOccurs="0" />
|
|
84
|
+
<xs:element name="Detail" type="tns:detail" minOccurs="0" />
|
|
85
|
+
</xs:sequence>
|
|
86
|
+
</xs:complexType>
|
|
87
|
+
|
|
88
|
+
<xs:complexType name="faultreason" >
|
|
89
|
+
<xs:sequence>
|
|
90
|
+
<xs:element name="Text" type="tns:reasontext"
|
|
91
|
+
minOccurs="1" maxOccurs="unbounded" />
|
|
92
|
+
</xs:sequence>
|
|
93
|
+
</xs:complexType>
|
|
94
|
+
|
|
95
|
+
<xs:complexType name="reasontext" >
|
|
96
|
+
<xs:simpleContent>
|
|
97
|
+
<xs:extension base="xs:string" >
|
|
98
|
+
<xs:attribute ref="xml:lang" use="required" />
|
|
99
|
+
</xs:extension>
|
|
100
|
+
</xs:simpleContent>
|
|
101
|
+
</xs:complexType>
|
|
102
|
+
|
|
103
|
+
<xs:complexType name="faultcode">
|
|
104
|
+
<xs:sequence>
|
|
105
|
+
<xs:element name="Value"
|
|
106
|
+
type="tns:faultcodeEnum"/>
|
|
107
|
+
<xs:element name="Subcode"
|
|
108
|
+
type="tns:subcode"
|
|
109
|
+
minOccurs="0"/>
|
|
110
|
+
</xs:sequence>
|
|
111
|
+
</xs:complexType>
|
|
112
|
+
|
|
113
|
+
<xs:simpleType name="faultcodeEnum">
|
|
114
|
+
<xs:restriction base="xs:QName">
|
|
115
|
+
<xs:enumeration value="tns:DataEncodingUnknown"/>
|
|
116
|
+
<xs:enumeration value="tns:MustUnderstand"/>
|
|
117
|
+
<xs:enumeration value="tns:Receiver"/>
|
|
118
|
+
<xs:enumeration value="tns:Sender"/>
|
|
119
|
+
<xs:enumeration value="tns:VersionMismatch"/>
|
|
120
|
+
</xs:restriction>
|
|
121
|
+
</xs:simpleType>
|
|
122
|
+
|
|
123
|
+
<xs:complexType name="subcode">
|
|
124
|
+
<xs:sequence>
|
|
125
|
+
<xs:element name="Value"
|
|
126
|
+
type="xs:QName"/>
|
|
127
|
+
<xs:element name="Subcode"
|
|
128
|
+
type="tns:subcode"
|
|
129
|
+
minOccurs="0"/>
|
|
130
|
+
</xs:sequence>
|
|
131
|
+
</xs:complexType>
|
|
132
|
+
|
|
133
|
+
<xs:complexType name="detail">
|
|
134
|
+
<xs:sequence>
|
|
135
|
+
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
|
|
136
|
+
</xs:sequence>
|
|
137
|
+
<xs:anyAttribute namespace="##other" processContents="lax" />
|
|
138
|
+
</xs:complexType>
|
|
139
|
+
|
|
140
|
+
<!-- Global element declaration and complex type definition for header entry returned due to a mustUnderstand fault -->
|
|
141
|
+
<xs:element name="NotUnderstood" type="tns:NotUnderstoodType" />
|
|
142
|
+
<xs:complexType name="NotUnderstoodType" >
|
|
143
|
+
<xs:attribute name="qname" type="xs:QName" use="required" />
|
|
144
|
+
</xs:complexType>
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
<!-- Global element and associated types for managing version transition as described in Appendix A of the SOAP Version 1.2 Part 1 Recommendation --> <xs:complexType name="SupportedEnvType" >
|
|
148
|
+
<xs:attribute name="qname" type="xs:QName" use="required" />
|
|
149
|
+
</xs:complexType>
|
|
150
|
+
|
|
151
|
+
<xs:element name="Upgrade" type="tns:UpgradeType" />
|
|
152
|
+
<xs:complexType name="UpgradeType" >
|
|
153
|
+
<xs:sequence>
|
|
154
|
+
<xs:element name="SupportedEnvelope" type="tns:SupportedEnvType" minOccurs="1" maxOccurs="unbounded" />
|
|
155
|
+
</xs:sequence>
|
|
156
|
+
</xs:complexType>
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
</xs:schema>
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
package/test/test.js
CHANGED
|
@@ -455,16 +455,106 @@ for (const element of doc.children) {
|
|
|
455
455
|
|
|
456
456
|
function test_013_soap () {
|
|
457
457
|
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
// console.log (xs)
|
|
458
|
+
const xs11 = new XMLSchemata ('test/soap-1.1.xsd')
|
|
461
459
|
|
|
460
|
+
// console.log (xs.get ('http://schemas.xmlsoap.org/soap/envelope/'))
|
|
461
|
+
// console.log (xs.get ('http://schemas.xmlsoap.org/soap/envelope/').getType ('Fault').children[0].children)
|
|
462
|
+
// console.log (xs.getType ('Fault'))
|
|
463
|
+
|
|
464
|
+
/*
|
|
462
465
|
console.log (xs.stringify ({
|
|
463
466
|
Envelope: {
|
|
464
467
|
Body: {null: {'<foo>bar</foo>': {Id: 1}}},
|
|
465
468
|
}
|
|
466
469
|
}))
|
|
467
470
|
|
|
471
|
+
|
|
472
|
+
<faultcode>SOAP-ENV:Client</faultcode>
|
|
473
|
+
<faultstring>Message does not have necessary info</faultstring>
|
|
474
|
+
<faultactor>http://gizmos.com/order</faultactor>
|
|
475
|
+
<detail>
|
|
476
|
+
<PO:order xmlns:PO="http://gizmos.com/orders/">Quantity element does not have a value</PO:order>
|
|
477
|
+
<PO:confirmation xmlns:PO="http://gizmos.com/confirm">Incomplete address: no zip code</PO:confirmation>
|
|
478
|
+
</detail>
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
*/
|
|
482
|
+
|
|
483
|
+
let Fault = {
|
|
484
|
+
faultcode: 'SOAP-ENV:Client',
|
|
485
|
+
faultstring: 'Message does not have necessary info',
|
|
486
|
+
faultactor: 'http://gizmos.com/order',
|
|
487
|
+
detail: {
|
|
488
|
+
null: {
|
|
489
|
+
[`
|
|
490
|
+
<PO:order xmlns:PO="http://gizmos.com/orders/">Quantity element does not have a value</PO:order>
|
|
491
|
+
<PO:confirmation xmlns:PO="http://gizmos.com/confirm">Incomplete address: no zip code</PO:confirmation>
|
|
492
|
+
`]: {}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const soap11 = {
|
|
498
|
+
Envelope: {
|
|
499
|
+
Body: {
|
|
500
|
+
null: {
|
|
501
|
+
[xs11.stringify ({Fault})]: {}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/*
|
|
508
|
+
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
|
|
509
|
+
<env:Header/>
|
|
510
|
+
<env:Body>
|
|
511
|
+
<env:Fault>
|
|
512
|
+
<env:Code>
|
|
513
|
+
<env:Value>env:Sender</env:Value>
|
|
514
|
+
</env:Code>
|
|
515
|
+
<env:Reason>
|
|
516
|
+
<env:Text xml:lang="en-US">Message does not have necessary info</env:Text>
|
|
517
|
+
</env:Reason>
|
|
518
|
+
<env:Role>http://gizmos.com/order</env:Role>
|
|
519
|
+
<env:Detail>
|
|
520
|
+
<PO:order xmlns:PO="http://gizmos.com/orders/">Quantity element does not have a value</PO:order>
|
|
521
|
+
<PO:confirmation xmlns:PO="http://gizmos.com/confirm">Incomplete address: no zip code</PO:confirmation>
|
|
522
|
+
</env:Detail>
|
|
523
|
+
</env:Fault>
|
|
524
|
+
</env:Body>
|
|
525
|
+
</env:Envelope>
|
|
526
|
+
*/
|
|
527
|
+
|
|
528
|
+
console.log (xs11.stringify (soap11))
|
|
529
|
+
|
|
530
|
+
const xs12 = new XMLSchemata ('test/soap-1.2.xsd')
|
|
531
|
+
|
|
532
|
+
Fault = {
|
|
533
|
+
Code: {Value: 'env:Sender'},
|
|
534
|
+
Reason: {Text: 'Message does not have necessary info'},
|
|
535
|
+
Role: 'http://gizmos.com/order',
|
|
536
|
+
Detail: {
|
|
537
|
+
null: {
|
|
538
|
+
[`
|
|
539
|
+
<PO:order xmlns:PO="http://gizmos.com/orders/">Quantity element does not have a value</PO:order>
|
|
540
|
+
<PO:confirmation xmlns:PO="http://gizmos.com/confirm">Incomplete address: no zip code</PO:confirmation>
|
|
541
|
+
`]: {}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const soap12 = {
|
|
547
|
+
Envelope: {
|
|
548
|
+
Body: {
|
|
549
|
+
null: {
|
|
550
|
+
[xs12.stringify ({Fault})]: {}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
console.log (xs12.stringify (soap12))
|
|
557
|
+
|
|
468
558
|
}
|
|
469
559
|
|
|
470
560
|
|
|
@@ -482,11 +572,13 @@ async function main () {
|
|
|
482
572
|
// await test_003_emitter_sync ('not-sa01.xml')
|
|
483
573
|
// await test_003_emitter_sync ('ent.xml')
|
|
484
574
|
// await test_003_emitter_sync ('soap.xml')
|
|
485
|
-
|
|
486
|
-
await
|
|
487
|
-
await
|
|
488
|
-
await
|
|
489
|
-
await
|
|
575
|
+
|
|
576
|
+
// await test_004_schemata ()
|
|
577
|
+
// await test_005_schemata ()
|
|
578
|
+
// await test_006_schemata ()
|
|
579
|
+
// await test_007_wsdl ()
|
|
580
|
+
// await test_008_schemata ()
|
|
581
|
+
|
|
490
582
|
// test_009_schemata ('smev-message-exchange-service-1.1.xsd')
|
|
491
583
|
// test_009_schemata ('sign.xsd')
|
|
492
584
|
|
|
@@ -497,7 +589,7 @@ async function main () {
|
|
|
497
589
|
// test_012_parser ('param_types.xml')
|
|
498
590
|
// test_012_parser ('20040.wsdl')
|
|
499
591
|
|
|
500
|
-
|
|
592
|
+
test_013_soap ()
|
|
501
593
|
|
|
502
594
|
}
|
|
503
595
|
|