xml-twig 1.1.0 → 1.1.1

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 CHANGED
@@ -51,7 +51,7 @@ With option `{ namespaces : true }` you will get access to the `.namespace` prop
51
51
 
52
52
  ### Read XML Document
53
53
 
54
- - Read entire XML file at once
54
+ - **Read entire XML file at once**
55
55
 
56
56
  This module is designed to read huge XML-Files. Of course, it works also well for small files. First create the Twig parser. Then create a Stream and pipe it to the parser.
57
57
 
@@ -76,7 +76,7 @@ With option `{ namespaces : true }` you will get access to the `.namespace` prop
76
76
  // Output -> xml finished after 1 lines
77
77
  ```
78
78
 
79
- If you prefer events, then use `event` property instead of `function` in handler declaration:
79
+ If you prefer [events](https://nodejs.org/api/events.html), then use `event` property instead of `function` in handler declaration:
80
80
 
81
81
  ```
82
82
  const parser = twig.createParser({ tag: twig.Root, event: 'rootElement' }, { method: 'sax' })
@@ -88,7 +88,7 @@ With option `{ namespaces : true }` you will get access to the `.namespace` prop
88
88
  ```
89
89
 
90
90
 
91
- - Read XML Document in chucks
91
+ - **Read XML Document in chucks**
92
92
 
93
93
  The key feature of this module is to read and process XML files in chunks. You need to create handler functions for elements you like to process.
94
94
 
@@ -131,7 +131,7 @@ With option `{ namespaces : true }` you will get access to the `.namespace` prop
131
131
  web book at line 48
132
132
  ```
133
133
 
134
- - Read every element from XML Document
134
+ - **Read every element from XML Document**
135
135
 
136
136
  ```
137
137
  function anyHandler(elt) {
@@ -165,7 +165,7 @@ Be aware if you run methods like `elt.followingSibling()`, `elt.descendant()`, `
165
165
  `elt.root().children()[0].followingSibling()`
166
166
 
167
167
 
168
- - Read only parts from XML Document
168
+ - **Read only parts from XML Document**
169
169
 
170
170
  If you like to read only certain elements, use option `partial: true`. The `root` element is always read.
171
171
 
@@ -177,7 +177,7 @@ Be aware if you run methods like `elt.followingSibling()`, `elt.descendant()`, `
177
177
  { tag: twig.Root, function: rootHandler }
178
178
  ];
179
179
  const parser = twig.createParser(handle_ebook, { partial: true })
180
- fs.createReadStream(`${__dirname}/samples/bookstore.xml`).pipe(parser);
180
+ fs.createReadStream(`${__dirname}/bookstore.xml`).pipe(parser);
181
181
 
182
182
  function ebookHandler(elt) {
183
183
  console.log(`${elt.name} at line ${parser.currentLine}`)
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  },
6
6
  "name": "xml-twig",
7
7
  "description": "Node module for processing huge XML documents in tree mode",
8
- "version": "1.1.0",
8
+ "version": "1.1.1",
9
9
  "main": "twig.js",
10
10
  "directories": {
11
11
  "doc": "doc"
@@ -1,10 +1,11 @@
1
1
  const fs = require('fs');
2
2
  const process = require('process');
3
+ const twig = require('xml-twig');
3
4
 
4
5
  let NE = 0;
5
6
  console.log('Starting...')
6
- let parser = require('xml-twig').createParser([{ name: 'subsession', function: anyHandler }], { method: 'expat' })
7
- let reader = fs.createReadStream(`${__dirname}/../samples/20231019015552.1-MSRAN.xml`);
7
+ let parser = twig.createParser([{ tag: 'subsession', function: anyHandler }], { method: 'expat' })
8
+ let reader = fs.createReadStream(`${__dirname}/20231019015552.1-MSRAN.xml`);
8
9
  reader.pipe(parser);
9
10
 
10
11
  function anyHandler(elt) {
package/samples/sample.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const twig = require('../twig.js');
3
3
 
4
- /*
4
+
5
5
  // Sample 1.1
6
6
  function rootHandler(elt) {
7
7
  console.log(`<${elt.name}> finished after ${parser.currentLine} lines`);
@@ -67,7 +67,7 @@ parser = twig.createParser({ tag: twig.Any, function: anyHandler })
67
67
  // or with Regular Expression: `{ tag: tag: /i/, function: anyHandler }`
68
68
  // or with Function: `{ tag: () => {return true}, function: anyHandler }`
69
69
  fs.createReadStream(`${__dirname}/bookstore.xml`).pipe(parser)
70
- */
70
+
71
71
 
72
72
  // Sample 5
73
73
  const handle_ebook = [
@@ -1,11 +1,12 @@
1
1
  const { DateTime } = require('luxon');
2
- const startTime = DateTime.now();
3
2
  const fs = require('fs');
3
+ const twig = require('xml-twig');
4
4
 
5
5
  let NE = 0;
6
+ const startTime = DateTime.now();
6
7
  console.log('Starting...')
7
- let parser = require('xml-twig').createParser([{ name: 'subsession', function: anyHandler }], { method: 'expat' })
8
- let reader = fs.createReadStream(`${__dirname}/../samples/20231019015552.1-MSRAN.xml`);
8
+ let parser = twig.createParser([{ tag: 'subsession', function: anyHandler }], { method: 'expat' })
9
+ let reader = fs.createReadStream(`${__dirname}/20231019015552.1-MSRAN.xml`);
9
10
  reader.pipe(parser);
10
11
 
11
12
  function anyHandler(elt) {