xml-toolkit 1.0.22 → 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.
@@ -82,7 +82,7 @@ const XMLMarshaller = class {
82
82
 
83
83
  }
84
84
 
85
- const {type} = node.attributes; if (type) this.appendAttributes (this.xs.getByReference (type), data)
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.getByReference (attributes.base), data, restriction)
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.getByReference (type), data)
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
 
@@ -162,17 +162,11 @@ 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
 
175
- this.appendScalar (this.xs.getByReference (type), v)
169
+ this.appendScalar (this.xs.getType (type), v)
176
170
 
177
171
  }
178
172
  else {
@@ -187,7 +181,7 @@ const XMLMarshaller = class {
187
181
 
188
182
  case 'extension':
189
183
 
190
- this.appendAttributes (this.xs.getByReference (attributes.base), data)
184
+ this.appendAttributes (this.xs.getType (attributes.base), data)
191
185
 
192
186
  case 'any':
193
187
  case 'sequence':
@@ -239,7 +233,7 @@ const XMLMarshaller = class {
239
233
 
240
234
  case 'extension':
241
235
 
242
- this.appendContent (this.xs.getByReference (attributes.base), data)
236
+ this.appendContent (this.xs.getType (attributes.base), data)
243
237
 
244
238
  default:
245
239
 
package/lib/XMLSchema.js CHANGED
@@ -1,3 +1,8 @@
1
+ const TYPES = Symbol ('_types')
2
+
3
+ const FORM_U = 'unqualified'
4
+ const FORM_Q = 'qualified'
5
+
1
6
  const XMLSchema = class extends Map {
2
7
 
3
8
  constructor (parent, targetNamespace) {
@@ -5,29 +10,41 @@ const XMLSchema = class extends Map {
5
10
  super ()
6
11
 
7
12
  this.parent = parent
13
+
8
14
  this.targetNamespace = targetNamespace
9
15
 
10
- this.isDefaultElementFormQualified = true
11
- this.isAttributeElementFormQualified = false
16
+ this.formDefault = {}
17
+
18
+ this [TYPES] = new Map ()
12
19
 
13
20
  }
21
+
22
+ getType (localName) {
23
+ return this [TYPES].get (localName)
24
+ }
14
25
 
15
26
  add (node, options = {}) {
16
-
17
- this.copyTargetNamespace (node)
18
-
27
+
19
28
  const {attributes, children} = node
29
+
30
+ for (const name of ['element', 'attribute']) this.formDefault [name] = attributes [name + 'FormDefault'] || FORM_U
20
31
 
21
- if (attributes.elementFormDefault === 'unqualified') this.isDefaultElementFormQualified = false
22
- if (attributes.attributeFormDefault === 'qualified') this.isAttributeElementFormQualified = true
32
+ this.copyTargetNamespace (node)
23
33
 
24
34
  for (const e of children) {
25
-
26
- const {attributes} = e; if (!('name' in attributes)) continue
35
+
36
+ const {localName, attributes} = e; if (!('name' in attributes)) continue
27
37
 
28
38
  const {name} = attributes
29
-
30
- this.set (name, e)
39
+
40
+ switch (localName) {
41
+ case 'complexType':
42
+ case 'simpleType':
43
+ this [TYPES].set (name, e)
44
+ break
45
+ default:
46
+ this.set (name, e)
47
+ }
31
48
 
32
49
  this.parent.register (name, this.targetNamespace)
33
50
 
@@ -35,13 +52,27 @@ const XMLSchema = class extends Map {
35
52
 
36
53
  }
37
54
 
38
- copyTargetNamespace (node) {
55
+ copyTargetNamespace (node, force = false) {
39
56
 
40
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
+ }
41
74
 
42
- node.targetNamespace = this.targetNamespace
43
-
44
- for (const e of node.children) this.copyTargetNamespace (e)
75
+ node.targetNamespace = this.targetNamespace
45
76
 
46
77
  }
47
78
 
@@ -40,10 +40,10 @@ const XMLSchemata = class extends Map {
40
40
 
41
41
  }
42
42
 
43
- getByReference (ref) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-toolkit",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "Collection of classes for dealing with XML",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -57,8 +57,8 @@ The name and trademarks of copyright holders may NOT be used in advertising or p
57
57
  </xs:complexType>
58
58
 
59
59
 
60
- <xs:element name="Body" type="tns:Body_" />
61
- <xs:complexType name="Body_" >
60
+ <xs:element name="Body" type="tns:Body" />
61
+ <xs:complexType name="Body" >
62
62
  <xs:sequence>
63
63
  <xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
64
64
  </xs:sequence>
@@ -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 xs = new XMLSchemata ('test/soap.xsd')
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')
575
+
485
576
  // await test_004_schemata ()
486
577
  // await test_005_schemata ()
487
578
  // await test_006_schemata ()
488
579
  // await test_007_wsdl ()
489
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
- test_013_soap ()
592
+ test_013_soap ()
501
593
 
502
594
  }
503
595