xml-toolkit 0.0.5 → 0.0.6

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/SAXEvent.js CHANGED
@@ -96,6 +96,20 @@ const SAXEvent = class {
96
96
  }
97
97
 
98
98
  }
99
+
100
+ get xml () {
101
+
102
+ switch (this.type) {
103
+
104
+ case END_DOCUMENT: return ''
105
+
106
+ case END_ELEMENT: return this.isSelfEnclosed ? '' : `</${this.name}>`
107
+
108
+ default: return this.src
109
+
110
+ }
111
+
112
+ }
99
113
 
100
114
  get attributes () {
101
115
 
package/lib/XMLNode.js CHANGED
@@ -25,6 +25,19 @@ const XMLNode = class extends SAXEvent {
25
25
 
26
26
  }
27
27
 
28
+ cloneStart () {
29
+
30
+ let e = new XMLNode (this.src, this [XML_READER], SAXEvent.TYPES.START_ELEMENT)
31
+
32
+ e [PARENT] = this [PARENT]
33
+ e [LEVEL] = this [LEVEL]
34
+ e [ATTRIBUTES] = this [ATTRIBUTES]
35
+ e [NS_MAP] = this [NS_MAP]
36
+
37
+ return e
38
+
39
+ }
40
+
28
41
  get level () {
29
42
 
30
43
  return this [LEVEL]
package/lib/XMLReader.js CHANGED
@@ -123,7 +123,7 @@ const XMLReader = class extends Transform {
123
123
 
124
124
  this.flush_text ()
125
125
 
126
- this.publish ({type: SAXEvent.TYPES.END_DOCUMENT})
126
+ this.publish (new XMLNode ('', this), SAXEvent.TYPES.END_DOCUMENT)
127
127
 
128
128
  callback ()
129
129
 
@@ -234,7 +234,7 @@ const XMLReader = class extends Transform {
234
234
 
235
235
  if (isStart && this.useNamespaces) e.readNamespaces ()
236
236
 
237
- this.publish (e)
237
+ this.publish (isStart ? e.cloneStart () : e)
238
238
 
239
239
  if (isStart) {
240
240
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-toolkit",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Collection of classes for dealing with XML",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/test.js CHANGED
@@ -52,15 +52,15 @@ async function test_003_emitter_sync (fn) {
52
52
 
53
53
  const xml = fs.readFileSync (
54
54
  'test/' + fn
55
- // , 'utf-8'
55
+ , 'utf-8'
56
56
  )
57
57
 
58
58
  console.log (xml)
59
59
 
60
60
  const sax = new XMLReader ({
61
- stripSpace: true,
62
- filterElements: 'SendRequestRequest',
63
- map: MoxyLikeJsonEncoder ({wrap: 1})
61
+ // stripSpace: true,
62
+ // filterElements: 'SendRequestRequest',
63
+ // map: MoxyLikeJsonEncoder ({wrap: 1})
64
64
  })
65
65
 
66
66
  /*
@@ -85,15 +85,18 @@ console.log (xml)
85
85
  //console.log (sax)
86
86
  //console.log (sax.isSAX)
87
87
 
88
- /*
89
- for await (const e of sax) {
90
- console.log (e)
88
+
89
+ let s = ''
90
+ for await (const {type, src, xml, parent} of sax) {
91
+ s += xml
92
+ // console.log ([type, src, xml, (parent || {}).localName])
91
93
  }
92
- */
93
94
 
94
- const v = await sax.findFirst ()
95
+ console.log ([xml, s])
96
+
97
+ // const v = await sax.findFirst ()
95
98
 
96
- console.log (JSON.stringify (v, null, 2))
99
+ // console.log (JSON.stringify (v, null, 2))
97
100
 
98
101
  }
99
102