xml-toolkit 1.0.43 → 1.0.45
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/README.md +30 -4
- package/badges/coverage-branches.svg +1 -0
- package/badges/coverage-functions.svg +1 -0
- package/badges/coverage-jest coverage.svg +1 -0
- package/badges/coverage-lines.svg +1 -0
- package/badges/coverage-statements.svg +1 -0
- package/index.js +17 -0
- package/lib/AttributesMap.js +62 -21
- package/lib/EntityResolver.js +0 -2
- package/lib/MoxyLikeJsonEncoder.js +13 -17
- package/lib/NamespacePrefixesMap.js +11 -15
- package/lib/NamespacesMap.js +0 -6
- package/lib/SAXEvent.js +12 -55
- package/lib/SOAP11.js +10 -34
- package/lib/SOAP12.js +1 -1
- package/lib/SOAPEncoding.js +4 -3
- package/lib/XMLIterator.js +1 -1
- package/lib/XMLLexer.js +12 -19
- package/lib/XMLMarshaller.js +45 -243
- package/lib/XMLNode.js +41 -57
- package/lib/XMLParser.js +2 -3
- package/lib/XMLPrinter.js +9 -3
- package/lib/XMLReader.js +2 -14
- package/lib/XMLSchema.js +54 -52
- package/lib/XMLSchemaBuiltIn.js +29 -0
- package/lib/XMLSchemaXml.js +24 -0
- package/lib/XMLSchemata.js +84 -120
- package/lib/XSSimpleType.js +327 -0
- package/lib/soap-1.2.xsd +1 -3
- package/lib/xml.xsd +38 -0
- package/lib/xsd.xsd +57 -0
- package/package.json +2 -2
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
const NamespacePrefixesMap = require ('./NamespacePrefixesMap.js')
|
|
2
|
+
|
|
3
|
+
class XSSimpleType {
|
|
4
|
+
|
|
5
|
+
constructor (xs) {
|
|
6
|
+
|
|
7
|
+
this.xs = xs
|
|
8
|
+
this.patterns = []
|
|
9
|
+
this.fractionDigits = Infinity
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
blame (value) {
|
|
14
|
+
|
|
15
|
+
let s; try {
|
|
16
|
+
|
|
17
|
+
s = JSON.stringify (value)
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
catch (x) {
|
|
21
|
+
|
|
22
|
+
s = String (value)
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
throw Error (`Cannot stringify ${typeof value} ${s}`)
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
stringify (value) {
|
|
31
|
+
|
|
32
|
+
if (value == null) this.blame (value)
|
|
33
|
+
|
|
34
|
+
for (const s of this.strings (value)) if (this.test (s)) return s
|
|
35
|
+
|
|
36
|
+
this.blame (value)
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
* strings (value) {
|
|
41
|
+
|
|
42
|
+
yield String (value)
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
test (s) {
|
|
47
|
+
|
|
48
|
+
for (const pattern of this.patterns) if (!pattern.test (s)) return false
|
|
49
|
+
|
|
50
|
+
return true
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
restrict (entries) {
|
|
55
|
+
|
|
56
|
+
return class extends this.constructor {
|
|
57
|
+
|
|
58
|
+
constructor (xs) {
|
|
59
|
+
|
|
60
|
+
super (xs)
|
|
61
|
+
|
|
62
|
+
for (const {name, value} of entries) switch (name) {
|
|
63
|
+
|
|
64
|
+
case 'pattern':
|
|
65
|
+
this.patterns.push (new RegExp (value))
|
|
66
|
+
break
|
|
67
|
+
|
|
68
|
+
case 'fractionDigits':
|
|
69
|
+
this.fractionDigits = parseInt (value)
|
|
70
|
+
break
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
class XSSimpleTypeQName extends XSSimpleType {
|
|
83
|
+
|
|
84
|
+
stringify (value) {
|
|
85
|
+
|
|
86
|
+
if (typeof value !== 'object' || !('localName' in value)) this.blame (value)
|
|
87
|
+
|
|
88
|
+
const {xs} = this
|
|
89
|
+
|
|
90
|
+
if (!xs.ns) xs.ns = new NamespacePrefixesMap (xs)
|
|
91
|
+
|
|
92
|
+
return xs.ns.QName (value.localName, value.namespaceURI)
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
class XSSimpleTypeFloat extends XSSimpleType {
|
|
99
|
+
|
|
100
|
+
stringify (value) {
|
|
101
|
+
|
|
102
|
+
if (isNaN (value)) this.blame (value)
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
value === Infinity ? 'INF' :
|
|
106
|
+
value === -Infinity ? '-INF' :
|
|
107
|
+
super.stringify (value)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
class XSSimpleTypeDecimal extends XSSimpleType {
|
|
115
|
+
|
|
116
|
+
isValidNumber (num) {
|
|
117
|
+
|
|
118
|
+
return !Number.isNaN (num)
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
stringify (value) {
|
|
123
|
+
|
|
124
|
+
let num = value
|
|
125
|
+
|
|
126
|
+
const {fractionDigits} = this
|
|
127
|
+
|
|
128
|
+
switch (typeof value) {
|
|
129
|
+
|
|
130
|
+
case 'bigint':
|
|
131
|
+
return fractionDigits === 0 || fractionDigits === Infinity ?
|
|
132
|
+
String (value) :
|
|
133
|
+
`${value}.${'0'.repeat (fractionDigits)}`
|
|
134
|
+
|
|
135
|
+
case 'string':
|
|
136
|
+
num = parseFloat (value)
|
|
137
|
+
|
|
138
|
+
case 'number':
|
|
139
|
+
if (!this.isValidNumber (num)) this.blame (value)
|
|
140
|
+
return fractionDigits === Infinity ?
|
|
141
|
+
num.toString () :
|
|
142
|
+
num.toFixed (this.fractionDigits)
|
|
143
|
+
|
|
144
|
+
default:
|
|
145
|
+
this.blame (value)
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
class XSSimpleTypeInteger extends XSSimpleTypeDecimal {
|
|
154
|
+
|
|
155
|
+
constructor (xs) {
|
|
156
|
+
|
|
157
|
+
super (xs)
|
|
158
|
+
|
|
159
|
+
this.fractionDigits = 0
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
isValidNumber (num) {
|
|
164
|
+
|
|
165
|
+
return Number.isInteger (num)
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
class XSSimpleTypeBoolean extends XSSimpleType {
|
|
172
|
+
|
|
173
|
+
static toCanonical (value) {
|
|
174
|
+
|
|
175
|
+
switch (typeof value) {
|
|
176
|
+
|
|
177
|
+
case 'boolean': return value
|
|
178
|
+
|
|
179
|
+
case 'number':
|
|
180
|
+
switch (value) {
|
|
181
|
+
case 0: return false
|
|
182
|
+
case 1: return true
|
|
183
|
+
default: return null
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
case 'string':
|
|
187
|
+
|
|
188
|
+
switch (value) {
|
|
189
|
+
|
|
190
|
+
case '0':
|
|
191
|
+
case 'false':
|
|
192
|
+
return false
|
|
193
|
+
|
|
194
|
+
case '1':
|
|
195
|
+
case 'true':
|
|
196
|
+
return true
|
|
197
|
+
|
|
198
|
+
default:
|
|
199
|
+
return null
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
* strings (value) {
|
|
208
|
+
|
|
209
|
+
const c = XSSimpleTypeBoolean.toCanonical (value); if (c !== null) {
|
|
210
|
+
|
|
211
|
+
if (c) {
|
|
212
|
+
yield 'true'
|
|
213
|
+
yield '1'
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
yield 'false'
|
|
217
|
+
yield '0'
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
class XSSimpleTypeDT extends XSSimpleType {
|
|
227
|
+
|
|
228
|
+
adjust (value) {
|
|
229
|
+
|
|
230
|
+
return typeof value === 'string' ? value : new Date (value).toJSON ()
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
class XSSimpleTypeDate extends XSSimpleTypeDT {
|
|
237
|
+
|
|
238
|
+
* strings (value) {
|
|
239
|
+
|
|
240
|
+
value = this.adjust (value)
|
|
241
|
+
|
|
242
|
+
const ymd = value.substring (0, 10)
|
|
243
|
+
|
|
244
|
+
const {length} = value; if (length > 10) {
|
|
245
|
+
|
|
246
|
+
const pos = value.indexOf ('Z')
|
|
247
|
+
|
|
248
|
+
if (pos !== -1 && pos !== length - 1) yield ymd + value.substring (pos)
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
yield ymd
|
|
253
|
+
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
class XSSimpleTypeDateTime extends XSSimpleTypeDT {
|
|
259
|
+
|
|
260
|
+
adjust (value) {
|
|
261
|
+
|
|
262
|
+
value = super.adjust (value)
|
|
263
|
+
|
|
264
|
+
return value.length === 10 ? value + 'T00:00:00' : value
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
* strings (value) {
|
|
269
|
+
|
|
270
|
+
value = this.adjust (value)
|
|
271
|
+
|
|
272
|
+
yield value
|
|
273
|
+
|
|
274
|
+
if (value.length > 19) yield value.substring (0, 19)
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
XSSimpleType.forName = name => {
|
|
281
|
+
|
|
282
|
+
switch (name) {
|
|
283
|
+
|
|
284
|
+
case 'QName' : return XSSimpleTypeQName
|
|
285
|
+
|
|
286
|
+
case 'boolean' : return XSSimpleTypeBoolean
|
|
287
|
+
|
|
288
|
+
case 'date' : return XSSimpleTypeDate
|
|
289
|
+
|
|
290
|
+
case 'dateTime': return XSSimpleTypeDateTime
|
|
291
|
+
|
|
292
|
+
case 'decimal' : return XSSimpleTypeDecimal
|
|
293
|
+
|
|
294
|
+
case 'float' :
|
|
295
|
+
case 'double' :
|
|
296
|
+
return XSSimpleTypeFloat
|
|
297
|
+
|
|
298
|
+
case 'byte':
|
|
299
|
+
case 'int':
|
|
300
|
+
case 'integer':
|
|
301
|
+
case 'long':
|
|
302
|
+
case 'negativeInteger':
|
|
303
|
+
case 'nonNegativeInteger':
|
|
304
|
+
case 'nonPositiveInteger':
|
|
305
|
+
case 'positiveInteger':
|
|
306
|
+
case 'short':
|
|
307
|
+
case 'unsignedByte':
|
|
308
|
+
case 'unsignedInt':
|
|
309
|
+
case 'unsignedLong':
|
|
310
|
+
case 'unsignedShort':
|
|
311
|
+
return XSSimpleTypeInteger
|
|
312
|
+
|
|
313
|
+
default : return XSSimpleType
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
module.exports = {
|
|
319
|
+
XSSimpleType,
|
|
320
|
+
XSSimpleTypeFloat,
|
|
321
|
+
XSSimpleTypeBoolean,
|
|
322
|
+
XSSimpleTypeDate,
|
|
323
|
+
XSSimpleTypeDateTime,
|
|
324
|
+
XSSimpleTypeDecimal,
|
|
325
|
+
XSSimpleTypeQName,
|
|
326
|
+
XSSimpleTypeInteger,
|
|
327
|
+
}
|
package/lib/soap-1.2.xsd
CHANGED
|
@@ -19,10 +19,8 @@
|
|
|
19
19
|
xmlns:tns="http://www.w3.org/2003/05/soap-envelope"
|
|
20
20
|
targetNamespace="http://www.w3.org/2003/05/soap-envelope"
|
|
21
21
|
elementFormDefault="qualified" >
|
|
22
|
-
|
|
23
|
-
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
|
|
22
|
+
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
|
|
24
23
|
schemaLocation="http://www.w3.org/2001/xml.xsd"/>
|
|
25
|
-
-->
|
|
26
24
|
|
|
27
25
|
<!-- Envelope, header and body -->
|
|
28
26
|
<xs:element name="Envelope" type="tns:Envelope" />
|
package/lib/xml.xsd
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/XML/1998/namespace">
|
|
3
|
+
|
|
4
|
+
<xs:attribute name="lang">
|
|
5
|
+
<xs:simpleType>
|
|
6
|
+
<xs:union memberTypes="xs:language">
|
|
7
|
+
<xs:simpleType>
|
|
8
|
+
<xs:restriction base="xs:string">
|
|
9
|
+
<xs:enumeration value=""/>
|
|
10
|
+
</xs:restriction>
|
|
11
|
+
</xs:simpleType>
|
|
12
|
+
</xs:union>
|
|
13
|
+
</xs:simpleType>
|
|
14
|
+
</xs:attribute>
|
|
15
|
+
|
|
16
|
+
<xs:attribute name="space">
|
|
17
|
+
<xs:simpleType>
|
|
18
|
+
<xs:restriction base="xs:NCName">
|
|
19
|
+
<xs:enumeration value="default"/>
|
|
20
|
+
<xs:enumeration value="preserve"/>
|
|
21
|
+
</xs:restriction>
|
|
22
|
+
</xs:simpleType>
|
|
23
|
+
</xs:attribute>
|
|
24
|
+
|
|
25
|
+
<xs:attribute name="base" type="xs:anyURI">
|
|
26
|
+
</xs:attribute>
|
|
27
|
+
|
|
28
|
+
<xs:attribute name="id" type="xs:ID">
|
|
29
|
+
</xs:attribute>
|
|
30
|
+
|
|
31
|
+
<xs:attributeGroup name="specialAttrs">
|
|
32
|
+
<xs:attribute ref="xml:base"/>
|
|
33
|
+
<xs:attribute ref="xml:lang"/>
|
|
34
|
+
<xs:attribute ref="xml:space"/>
|
|
35
|
+
<xs:attribute ref="xml:id"/>
|
|
36
|
+
</xs:attributeGroup>
|
|
37
|
+
|
|
38
|
+
</xs:schema>
|
package/lib/xsd.xsd
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2001/XMLSchema">
|
|
3
|
+
|
|
4
|
+
<xs:simpleType name="anySimpleType" />
|
|
5
|
+
<xs:simpleType name="ENTITIES" />
|
|
6
|
+
<xs:simpleType name="IDREFS" />
|
|
7
|
+
<xs:simpleType name="NMTOKENS"/>
|
|
8
|
+
<xs:simpleType name="anyAtomicType"/>
|
|
9
|
+
<xs:simpleType name="dateTime" />
|
|
10
|
+
<xs:simpleType name="dateTimeStamp"/>
|
|
11
|
+
|
|
12
|
+
<xs:simpleType name="ENTITY" />
|
|
13
|
+
<xs:simpleType name="ID" />
|
|
14
|
+
<xs:simpleType name="IDREF" />
|
|
15
|
+
<xs:simpleType name="NCName" />
|
|
16
|
+
<xs:simpleType name="NMTOKEN" />
|
|
17
|
+
<xs:simpleType name="NOTATION" />
|
|
18
|
+
<xs:simpleType name="Name" />
|
|
19
|
+
<xs:simpleType name="QName" />
|
|
20
|
+
<xs:simpleType name="anyURI" />
|
|
21
|
+
<xs:simpleType name="base64Binary" />
|
|
22
|
+
<xs:simpleType name="boolean" />
|
|
23
|
+
<xs:simpleType name="byte" />
|
|
24
|
+
<xs:simpleType name="date" />
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<xs:simpleType name="dayTimeDuration" />
|
|
28
|
+
<xs:simpleType name="decimal" />
|
|
29
|
+
<xs:simpleType name="double" />
|
|
30
|
+
<xs:simpleType name="duration" />
|
|
31
|
+
<xs:simpleType name="float" />
|
|
32
|
+
<xs:simpleType name="gDay" />
|
|
33
|
+
<xs:simpleType name="gMonth" />
|
|
34
|
+
<xs:simpleType name="gMonthDay" />
|
|
35
|
+
<xs:simpleType name="gYear" />
|
|
36
|
+
<xs:simpleType name="gYearMonth" />
|
|
37
|
+
<xs:simpleType name="hexBinary" />
|
|
38
|
+
<xs:simpleType name="int" />
|
|
39
|
+
<xs:simpleType name="integer" />
|
|
40
|
+
<xs:simpleType name="language" />
|
|
41
|
+
<xs:simpleType name="long" />
|
|
42
|
+
<xs:simpleType name="negativeInteger" />
|
|
43
|
+
<xs:simpleType name="nonNegativeInteger" />
|
|
44
|
+
<xs:simpleType name="nonPositiveInteger" />
|
|
45
|
+
<xs:simpleType name="normalizedString" />
|
|
46
|
+
<xs:simpleType name="positiveInteger" />
|
|
47
|
+
<xs:simpleType name="short" />
|
|
48
|
+
<xs:simpleType name="string" />
|
|
49
|
+
<xs:simpleType name="time" />
|
|
50
|
+
<xs:simpleType name="token" />
|
|
51
|
+
<xs:simpleType name="unsignedByte" />
|
|
52
|
+
<xs:simpleType name="unsignedInt" />
|
|
53
|
+
<xs:simpleType name="unsignedLong" />
|
|
54
|
+
<xs:simpleType name="unsignedShort" />
|
|
55
|
+
<xs:simpleType name="yearMonthDuration" />
|
|
56
|
+
|
|
57
|
+
</xs:schema>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xml-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.45",
|
|
4
4
|
"description": "XML parser, marshaller, SOAP adapter",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -54,4 +54,4 @@
|
|
|
54
54
|
"http-errors": "^2.0.0",
|
|
55
55
|
"string-escape-map": "^1.0.0"
|
|
56
56
|
}
|
|
57
|
-
}
|
|
57
|
+
}
|