xml-toolkit 1.0.41 → 1.0.43

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.
@@ -1,5 +1,3 @@
1
- const CH_COLON = ':'.charCodeAt (0)
2
-
3
1
  const AttributesMap = class extends Map {
4
2
 
5
3
  constructor (entityResolver = null, nsMap = null) {
@@ -36,38 +34,16 @@ const AttributesMap = class extends Map {
36
34
  }
37
35
 
38
36
  }
39
-
37
+
40
38
  set (k, v) {
41
39
 
42
- const {_nsMap} = this; if (_nsMap !== null) {
43
-
44
- if (k.slice (0, 5) === 'xmlns') {
45
-
46
- if (k.length === 5) {
47
-
48
- _nsMap.set ('', v)
49
-
50
- return this
51
-
52
- }
53
-
54
- if (k.charCodeAt (5) === CH_COLON) {
55
-
56
- _nsMap.set (k.slice (6), v)
57
-
58
- return this
59
-
60
- }
61
-
62
- }
63
-
64
- }
65
-
66
- const {entityResolver} = this
40
+ const {_nsMap, entityResolver} = this
41
+
42
+ if (_nsMap !== null && k.startsWith ('xmlns') && _nsMap.processAttribute (k, v)) return this
67
43
 
68
44
  return super.set (k,
69
45
 
70
- v === '' ? null :
46
+ v === '' ? null :
71
47
 
72
48
  entityResolver === null ? v :
73
49
 
@@ -1,3 +1,5 @@
1
+ const CH_COLON = ':'.charCodeAt (0)
2
+
1
3
  const XMLNamespace = 'http://www.w3.org/XML/1998/namespace'
2
4
  const XMLNamespacePrefix = 'xml'
3
5
 
@@ -28,6 +30,25 @@ const NamespacesMap = class extends Map {
28
30
 
29
31
  }
30
32
 
33
+ processAttribute (key, value) {
34
+
35
+ if (key.length === 5) {
36
+
37
+ this.set ('', this.default = value)
38
+
39
+ }
40
+ else {
41
+
42
+ if (key.charCodeAt (5) !== CH_COLON) return false
43
+
44
+ this.set (key.slice (6), value)
45
+
46
+ }
47
+
48
+ return true
49
+
50
+ }
51
+
31
52
  getNamespaceURI (name, useDefault = false) {
32
53
 
33
54
  const pos = name.indexOf (':'), noColon = pos === -1
package/lib/XMLPrinter.js CHANGED
@@ -198,9 +198,11 @@ const XMLPrinter = class {
198
198
 
199
199
  this.openElement (node.name)
200
200
 
201
+ const {namespacesMap} = node; if (namespacesMap != null && namespacesMap.default) this.writeAttribute ('xmlns', namespacesMap.default)
202
+
201
203
  if (this.stack.length === 1) {
202
204
 
203
- const {namespacesMap} = node; if (namespacesMap != null) {
205
+ if (namespacesMap != null) {
204
206
 
205
207
  let min = Infinity; for (const name of namespacesMap.keys ()) {
206
208
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-toolkit",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "XML parser, marshaller, SOAP adapter",
5
5
  "main": "index.js",
6
6
  "files": [