xml-toolkit 1.0.22 → 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.
@@ -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
 
@@ -172,7 +172,7 @@ const XMLMarshaller = class {
172
172
 
173
173
  if (type) {
174
174
 
175
- this.appendScalar (this.xs.getByReference (type), v)
175
+ this.appendScalar (this.xs.getType (type), v)
176
176
 
177
177
  }
178
178
  else {
@@ -187,7 +187,7 @@ const XMLMarshaller = class {
187
187
 
188
188
  case 'extension':
189
189
 
190
- this.appendAttributes (this.xs.getByReference (attributes.base), data)
190
+ this.appendAttributes (this.xs.getType (attributes.base), data)
191
191
 
192
192
  case 'any':
193
193
  case 'sequence':
@@ -239,7 +239,7 @@ const XMLMarshaller = class {
239
239
 
240
240
  case 'extension':
241
241
 
242
- this.appendContent (this.xs.getByReference (attributes.base), data)
242
+ this.appendContent (this.xs.getType (attributes.base), data)
243
243
 
244
244
  default:
245
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
- this.set (name, e)
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
 
@@ -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.23",
4
4
  "description": "Collection of classes for dealing with XML",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/soap.xsd CHANGED
@@ -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>
package/test/test.js CHANGED
@@ -457,7 +457,7 @@ function test_013_soap () {
457
457
 
458
458
  const xs = new XMLSchemata ('test/soap.xsd')
459
459
 
460
- console.log (xs)
460
+ // console.log (xs)
461
461
 
462
462
  console.log (xs.stringify ({
463
463
  Envelope: {
@@ -482,11 +482,11 @@ async function main () {
482
482
  // await test_003_emitter_sync ('not-sa01.xml')
483
483
  // await test_003_emitter_sync ('ent.xml')
484
484
  // await test_003_emitter_sync ('soap.xml')
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 ()
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
490
  // test_009_schemata ('smev-message-exchange-service-1.1.xsd')
491
491
  // test_009_schemata ('sign.xsd')
492
492
 
@@ -497,7 +497,7 @@ async function main () {
497
497
  // test_012_parser ('param_types.xml')
498
498
  // test_012_parser ('20040.wsdl')
499
499
 
500
- test_013_soap ()
500
+ // test_013_soap ()
501
501
 
502
502
  }
503
503