xml-toolkit 1.0.21 → 1.0.23
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 +22 -6
- package/lib/XMLSchema.js +19 -4
- package/lib/XMLSchemata.js +11 -3
- package/package.json +1 -1
- package/test/soap.xsd +127 -0
- package/test/test.js +23 -6
package/lib/XMLMarshaller.js
CHANGED
|
@@ -82,7 +82,7 @@ const XMLMarshaller = class {
|
|
|
82
82
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
const {type} = node.attributes; if (type) this.appendAttributes (this.xs.
|
|
85
|
+
const {type} = node.attributes; if (type) this.appendAttributes (this.xs.getType (type), data)
|
|
86
86
|
|
|
87
87
|
this.appendAttributes (node, data)
|
|
88
88
|
|
|
@@ -116,7 +116,7 @@ const XMLMarshaller = class {
|
|
|
116
116
|
|
|
117
117
|
for (const {localName, attributes: {value}} of children) restriction [localName] = value
|
|
118
118
|
|
|
119
|
-
return this.appendScalar (this.xs.
|
|
119
|
+
return this.appendScalar (this.xs.getType (attributes.base), data, restriction)
|
|
120
120
|
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -130,7 +130,7 @@ const XMLMarshaller = class {
|
|
|
130
130
|
|
|
131
131
|
const {attributes: {type}, children} = node
|
|
132
132
|
|
|
133
|
-
if (type) return this.appendContent (this.xs.
|
|
133
|
+
if (type) return this.appendContent (this.xs.getType (type), data)
|
|
134
134
|
|
|
135
135
|
for (const i of children) this.appendContent (i, data)
|
|
136
136
|
|
|
@@ -144,6 +144,18 @@ const XMLMarshaller = class {
|
|
|
144
144
|
|
|
145
145
|
switch (localName) {
|
|
146
146
|
|
|
147
|
+
case 'anyAttribute':
|
|
148
|
+
|
|
149
|
+
if (null in data)
|
|
150
|
+
|
|
151
|
+
for (const o of Object.values (data [null]))
|
|
152
|
+
|
|
153
|
+
for (const [k, v] of Object.entries (o))
|
|
154
|
+
|
|
155
|
+
this.buf += ' ' + k + '="' + XML_ATTR.escape ('' + v) + '"'
|
|
156
|
+
|
|
157
|
+
break
|
|
158
|
+
|
|
147
159
|
case 'attribute':
|
|
148
160
|
|
|
149
161
|
if (!(name in data)) return
|
|
@@ -160,7 +172,7 @@ const XMLMarshaller = class {
|
|
|
160
172
|
|
|
161
173
|
if (type) {
|
|
162
174
|
|
|
163
|
-
this.appendScalar (this.xs.
|
|
175
|
+
this.appendScalar (this.xs.getType (type), v)
|
|
164
176
|
|
|
165
177
|
}
|
|
166
178
|
else {
|
|
@@ -175,7 +187,7 @@ const XMLMarshaller = class {
|
|
|
175
187
|
|
|
176
188
|
case 'extension':
|
|
177
189
|
|
|
178
|
-
this.appendAttributes (this.xs.
|
|
190
|
+
this.appendAttributes (this.xs.getType (attributes.base), data)
|
|
179
191
|
|
|
180
192
|
case 'any':
|
|
181
193
|
case 'sequence':
|
|
@@ -203,6 +215,10 @@ const XMLMarshaller = class {
|
|
|
203
215
|
|
|
204
216
|
switch (localName) {
|
|
205
217
|
|
|
218
|
+
case 'any':
|
|
219
|
+
if (null in data) for (const xml in data [null]) this.buf += xml
|
|
220
|
+
break
|
|
221
|
+
|
|
206
222
|
case 'simpleType':
|
|
207
223
|
|
|
208
224
|
return this.appendScalar (node, data)
|
|
@@ -223,7 +239,7 @@ const XMLMarshaller = class {
|
|
|
223
239
|
|
|
224
240
|
case 'extension':
|
|
225
241
|
|
|
226
|
-
this.appendContent (this.xs.
|
|
242
|
+
this.appendContent (this.xs.getType (attributes.base), data)
|
|
227
243
|
|
|
228
244
|
default:
|
|
229
245
|
|
package/lib/XMLSchema.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const TYPES = Symbol ('_types')
|
|
2
|
+
|
|
1
3
|
const XMLSchema = class extends Map {
|
|
2
4
|
|
|
3
5
|
constructor (parent, targetNamespace) {
|
|
@@ -9,8 +11,14 @@ const XMLSchema = class extends Map {
|
|
|
9
11
|
|
|
10
12
|
this.isDefaultElementFormQualified = true
|
|
11
13
|
this.isAttributeElementFormQualified = false
|
|
14
|
+
|
|
15
|
+
this [TYPES] = new Map ()
|
|
12
16
|
|
|
13
17
|
}
|
|
18
|
+
|
|
19
|
+
getType (localName) {
|
|
20
|
+
return this [TYPES].get (localName)
|
|
21
|
+
}
|
|
14
22
|
|
|
15
23
|
add (node, options = {}) {
|
|
16
24
|
|
|
@@ -22,12 +30,19 @@ const XMLSchema = class extends Map {
|
|
|
22
30
|
if (attributes.attributeFormDefault === 'qualified') this.isAttributeElementFormQualified = true
|
|
23
31
|
|
|
24
32
|
for (const e of children) {
|
|
25
|
-
|
|
26
|
-
const {attributes} = e; if (!('name' in attributes)) continue
|
|
33
|
+
|
|
34
|
+
const {localName, attributes} = e; if (!('name' in attributes)) continue
|
|
27
35
|
|
|
28
36
|
const {name} = attributes
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
|
|
38
|
+
switch (localName) {
|
|
39
|
+
case 'complexType':
|
|
40
|
+
case 'simpleType':
|
|
41
|
+
this [TYPES].set (name, e)
|
|
42
|
+
break
|
|
43
|
+
default:
|
|
44
|
+
this.set (name, e)
|
|
45
|
+
}
|
|
31
46
|
|
|
32
47
|
this.parent.register (name, this.targetNamespace)
|
|
33
48
|
|
package/lib/XMLSchemata.js
CHANGED
|
@@ -40,10 +40,10 @@ const XMLSchemata = class extends Map {
|
|
|
40
40
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
getType (ref) {
|
|
44
44
|
|
|
45
45
|
const [localName, namespaceURI] = ref
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
if (namespaceURI === XMLSchema.namespaceURI) return {
|
|
48
48
|
localName: 'simpleType',
|
|
49
49
|
namespaceURI,
|
|
@@ -53,10 +53,18 @@ const XMLSchemata = class extends Map {
|
|
|
53
53
|
targetNamespace: namespaceURI
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
return this.get (namespaceURI).getType (localName)
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getByReference (ref) {
|
|
61
|
+
|
|
62
|
+
const [localName, namespaceURI] = ref
|
|
63
|
+
|
|
56
64
|
return this.get (namespaceURI).get (localName)
|
|
57
65
|
|
|
58
66
|
}
|
|
59
|
-
|
|
67
|
+
|
|
60
68
|
getSchemaByLocalName (localName) {
|
|
61
69
|
|
|
62
70
|
const ns = this [IDX].get (localName)
|
package/package.json
CHANGED
package/test/soap.xsd
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8' ?>
|
|
2
|
+
|
|
3
|
+
<!-- Schema for the SOAP/1.1 envelope
|
|
4
|
+
|
|
5
|
+
Portions © 2001 DevelopMentor.
|
|
6
|
+
© 2001 W3C (Massachusetts Institute of Technology, Institut National de Recherche en Informatique et en Automatique, Keio University). All Rights Reserved.
|
|
7
|
+
|
|
8
|
+
This document is governed by the W3C Software License [1] as described in the FAQ [2].
|
|
9
|
+
[1] http://www.w3.org/Consortium/Legal/copyright-software-19980720
|
|
10
|
+
[2] http://www.w3.org/Consortium/Legal/IPR-FAQ-20000620.html#DTD
|
|
11
|
+
By obtaining, using and/or copying this work, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions:
|
|
12
|
+
|
|
13
|
+
Permission to use, copy, modify, and distribute this software and its documentation, with or without modification, for any purpose and without fee or royalty is hereby granted, provided that you include the following on ALL copies of the software and documentation or portions thereof, including modifications, that you make:
|
|
14
|
+
|
|
15
|
+
1. The full text of this NOTICE in a location viewable to users of the redistributed or derivative work.
|
|
16
|
+
|
|
17
|
+
2. Any pre-existing intellectual property disclaimers, notices, or terms and conditions. If none exist, a short notice of the following form (hypertext is preferred, text is permitted) should be used within the body of any redistributed or derivative code: "Copyright © 2001 World Wide Web Consortium, (Massachusetts Institute of Technology, Institut National de Recherche en Informatique et en Automatique, Keio University). All Rights Reserved. http://www.w3.org/Consortium/Legal/"
|
|
18
|
+
|
|
19
|
+
3. Notice of any changes or modifications to the W3C files, including the date changes were made. (We recommend you provide URIs to the location from which the code is derived.)
|
|
20
|
+
|
|
21
|
+
Original W3C files; http://www.w3.org/2001/06/soap-envelope
|
|
22
|
+
Changes made:
|
|
23
|
+
- reverted namespace to http://schemas.xmlsoap.org/soap/envelope/
|
|
24
|
+
- reverted mustUnderstand to only allow 0 and 1 as lexical values
|
|
25
|
+
- made encodingStyle a global attribute 20020825
|
|
26
|
+
- removed default value from mustUnderstand attribute declaration
|
|
27
|
+
|
|
28
|
+
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
|
29
|
+
|
|
30
|
+
COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
|
|
31
|
+
|
|
32
|
+
The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the software without specific, written prior permission. Title to copyright in this software and any associated documentation will at all times remain with copyright holders.
|
|
33
|
+
|
|
34
|
+
-->
|
|
35
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
36
|
+
xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/"
|
|
37
|
+
targetNamespace="http://schemas.xmlsoap.org/soap/envelope/" >
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
<!-- Envelope, header and body -->
|
|
41
|
+
<xs:element name="Envelope" type="tns:Envelope" />
|
|
42
|
+
<xs:complexType name="Envelope" >
|
|
43
|
+
<xs:sequence>
|
|
44
|
+
<xs:element ref="tns:Header" minOccurs="0" />
|
|
45
|
+
<xs:element ref="tns:Body" minOccurs="1" />
|
|
46
|
+
<xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
|
|
47
|
+
</xs:sequence>
|
|
48
|
+
<xs:anyAttribute namespace="##other" processContents="lax" />
|
|
49
|
+
</xs:complexType>
|
|
50
|
+
|
|
51
|
+
<xs:element name="Header" type="tns:Header" />
|
|
52
|
+
<xs:complexType name="Header" >
|
|
53
|
+
<xs:sequence>
|
|
54
|
+
<xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
|
|
55
|
+
</xs:sequence>
|
|
56
|
+
<xs:anyAttribute namespace="##other" processContents="lax" />
|
|
57
|
+
</xs:complexType>
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
<xs:element name="Body" type="tns:Body" />
|
|
61
|
+
<xs:complexType name="Body" >
|
|
62
|
+
<xs:sequence>
|
|
63
|
+
<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
|
|
64
|
+
</xs:sequence>
|
|
65
|
+
<xs:anyAttribute namespace="##any" processContents="lax" >
|
|
66
|
+
<xs:annotation>
|
|
67
|
+
<xs:documentation>
|
|
68
|
+
Prose in the spec does not specify that attributes are allowed on the Body element
|
|
69
|
+
</xs:documentation>
|
|
70
|
+
</xs:annotation>
|
|
71
|
+
</xs:anyAttribute>
|
|
72
|
+
</xs:complexType>
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
<!-- Global Attributes. The following attributes are intended to be usable via qualified attribute names on any complex type referencing them. -->
|
|
76
|
+
<xs:attribute name="mustUnderstand" >
|
|
77
|
+
<xs:simpleType>
|
|
78
|
+
<xs:restriction base='xs:boolean'>
|
|
79
|
+
<xs:pattern value='0|1' />
|
|
80
|
+
</xs:restriction>
|
|
81
|
+
</xs:simpleType>
|
|
82
|
+
</xs:attribute>
|
|
83
|
+
<xs:attribute name="actor" type="xs:anyURI" />
|
|
84
|
+
|
|
85
|
+
<xs:simpleType name="encodingStyle" >
|
|
86
|
+
<xs:annotation>
|
|
87
|
+
<xs:documentation>
|
|
88
|
+
'encodingStyle' indicates any canonicalization conventions followed in the contents of the containing element. For example, the value 'http://schemas.xmlsoap.org/soap/encoding/' indicates the pattern described in SOAP specification
|
|
89
|
+
</xs:documentation>
|
|
90
|
+
</xs:annotation>
|
|
91
|
+
<xs:list itemType="xs:anyURI" />
|
|
92
|
+
</xs:simpleType>
|
|
93
|
+
|
|
94
|
+
<xs:attribute name="encodingStyle" type="tns:encodingStyle" />
|
|
95
|
+
<xs:attributeGroup name="encodingStyle" >
|
|
96
|
+
<xs:attribute ref="tns:encodingStyle" />
|
|
97
|
+
</xs:attributeGroup>
|
|
98
|
+
|
|
99
|
+
<xs:element name="Fault" type="tns:Fault" />
|
|
100
|
+
<xs:complexType name="Fault" final="extension" >
|
|
101
|
+
<xs:annotation>
|
|
102
|
+
<xs:documentation>
|
|
103
|
+
Fault reporting structure
|
|
104
|
+
</xs:documentation>
|
|
105
|
+
</xs:annotation>
|
|
106
|
+
<xs:sequence>
|
|
107
|
+
<xs:element name="faultcode" type="xs:QName" />
|
|
108
|
+
<xs:element name="faultstring" type="xs:string" />
|
|
109
|
+
<xs:element name="faultactor" type="xs:anyURI" minOccurs="0" />
|
|
110
|
+
<xs:element name="detail" type="tns:detail" minOccurs="0" />
|
|
111
|
+
</xs:sequence>
|
|
112
|
+
</xs:complexType>
|
|
113
|
+
|
|
114
|
+
<xs:complexType name="detail">
|
|
115
|
+
<xs:sequence>
|
|
116
|
+
<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
|
|
117
|
+
</xs:sequence>
|
|
118
|
+
<xs:anyAttribute namespace="##any" processContents="lax" />
|
|
119
|
+
</xs:complexType>
|
|
120
|
+
|
|
121
|
+
</xs:schema>
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
package/test/test.js
CHANGED
|
@@ -453,6 +453,21 @@ for (const element of doc.children) {
|
|
|
453
453
|
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
function test_013_soap () {
|
|
457
|
+
|
|
458
|
+
const xs = new XMLSchemata ('test/soap.xsd')
|
|
459
|
+
|
|
460
|
+
// console.log (xs)
|
|
461
|
+
|
|
462
|
+
console.log (xs.stringify ({
|
|
463
|
+
Envelope: {
|
|
464
|
+
Body: {null: {'<foo>bar</foo>': {Id: 1}}},
|
|
465
|
+
}
|
|
466
|
+
}))
|
|
467
|
+
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
|
|
456
471
|
async function main () {
|
|
457
472
|
|
|
458
473
|
// await test_001_lexer_sync ('E05a.xml')
|
|
@@ -467,12 +482,12 @@ async function main () {
|
|
|
467
482
|
// await test_003_emitter_sync ('not-sa01.xml')
|
|
468
483
|
// await test_003_emitter_sync ('ent.xml')
|
|
469
484
|
// await test_003_emitter_sync ('soap.xml')
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
test_009_schemata ('smev-message-exchange-service-1.1.xsd')
|
|
485
|
+
await test_004_schemata ()
|
|
486
|
+
await test_005_schemata ()
|
|
487
|
+
await test_006_schemata ()
|
|
488
|
+
await test_007_wsdl ()
|
|
489
|
+
await test_008_schemata ()
|
|
490
|
+
// test_009_schemata ('smev-message-exchange-service-1.1.xsd')
|
|
476
491
|
// test_009_schemata ('sign.xsd')
|
|
477
492
|
|
|
478
493
|
// test_010_node ()
|
|
@@ -481,6 +496,8 @@ async function main () {
|
|
|
481
496
|
|
|
482
497
|
// test_012_parser ('param_types.xml')
|
|
483
498
|
// test_012_parser ('20040.wsdl')
|
|
499
|
+
|
|
500
|
+
// test_013_soap ()
|
|
484
501
|
|
|
485
502
|
}
|
|
486
503
|
|