xml-twig 1.1.0 → 1.1.2
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 +7 -7
- package/doc/build.sh +6 -6
- package/package.json +38 -38
- package/samples/memory-test.js +3 -2
- package/samples/sample.js +2 -2
- package/samples/speed-test.js +4 -3
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) {
|
|
@@ -140,7 +140,7 @@ With option `{ namespaces : true }` you will get access to the `.namespace` prop
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
const parser = twig.createParser({ tag: twig.Any, function: anyHandler })
|
|
143
|
-
// or with Regular Expression -> `{ tag:
|
|
143
|
+
// or with Regular Expression -> `{ tag: /./, function: anyHandler }`
|
|
144
144
|
// or with Function -> `{ tag: () => {return true}, function: anyHandler }`
|
|
145
145
|
fs.createReadStream(`${__dirname}/bookstore.xml`).pipe(parser)
|
|
146
146
|
|
|
@@ -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}/
|
|
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/doc/build.sh
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
jsdoc2md --private ../twig.js > ./twig.md
|
|
4
|
-
|
|
5
|
-
# see https://github.com/jsdoc2md/jsdoc-to-markdown
|
|
6
|
-
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
jsdoc2md --private ../twig.js > ./twig.md
|
|
4
|
+
|
|
5
|
+
# see https://github.com/jsdoc2md/jsdoc-to-markdown
|
|
6
|
+
|
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"dependencies": {
|
|
3
|
-
"sax": "^1.3.0",
|
|
4
|
-
"xml-writer": "^1.7.0"
|
|
5
|
-
},
|
|
6
|
-
"name": "xml-twig",
|
|
7
|
-
"description": "Node module for processing huge XML documents in tree mode",
|
|
8
|
-
"version": "1.1.
|
|
9
|
-
"main": "twig.js",
|
|
10
|
-
"directories": {
|
|
11
|
-
"doc": "doc"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"jsdoc-to-markdown": "^8.0.0",
|
|
15
|
-
"luxon": "^2.1.1",
|
|
16
|
-
"node-expat": "^2.4.0"
|
|
17
|
-
},
|
|
18
|
-
"scripts": {
|
|
19
|
-
"test": "node demo.js"
|
|
20
|
-
},
|
|
21
|
-
"repository": {
|
|
22
|
-
"type": "git",
|
|
23
|
-
"url": "git+https://github.com/Wernfried/xml-twig.git"
|
|
24
|
-
},
|
|
25
|
-
"keywords": [
|
|
26
|
-
"xml",
|
|
27
|
-
"sax",
|
|
28
|
-
"expat",
|
|
29
|
-
"parser",
|
|
30
|
-
"xml-reader"
|
|
31
|
-
],
|
|
32
|
-
"author": "Wernfried Domscheit",
|
|
33
|
-
"license": "ISC",
|
|
34
|
-
"bugs": {
|
|
35
|
-
"url": "https://github.com/Wernfried/xml-twig/issues"
|
|
36
|
-
},
|
|
37
|
-
"homepage": "https://github.com/Wernfried/xml-twig#readme"
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"sax": "^1.3.0",
|
|
4
|
+
"xml-writer": "^1.7.0"
|
|
5
|
+
},
|
|
6
|
+
"name": "xml-twig",
|
|
7
|
+
"description": "Node module for processing huge XML documents in tree mode",
|
|
8
|
+
"version": "1.1.2",
|
|
9
|
+
"main": "twig.js",
|
|
10
|
+
"directories": {
|
|
11
|
+
"doc": "doc"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"jsdoc-to-markdown": "^8.0.0",
|
|
15
|
+
"luxon": "^2.1.1",
|
|
16
|
+
"node-expat": "^2.4.0"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "node demo.js"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Wernfried/xml-twig.git"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"xml",
|
|
27
|
+
"sax",
|
|
28
|
+
"expat",
|
|
29
|
+
"parser",
|
|
30
|
+
"xml-reader"
|
|
31
|
+
],
|
|
32
|
+
"author": "Wernfried Domscheit",
|
|
33
|
+
"license": "ISC",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/Wernfried/xml-twig/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/Wernfried/xml-twig#readme"
|
|
38
|
+
}
|
package/samples/memory-test.js
CHANGED
|
@@ -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 =
|
|
7
|
-
let reader = fs.createReadStream(`${__dirname}
|
|
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 = [
|
package/samples/speed-test.js
CHANGED
|
@@ -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 =
|
|
8
|
-
let reader = fs.createReadStream(`${__dirname}
|
|
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) {
|