xml-twig 1.3.13 → 1.3.16
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 +0 -7
- package/package.json +1 -1
- package/twig.js +4 -3
package/README.md
CHANGED
|
@@ -57,13 +57,6 @@ API Documentation: see [Twig](./doc/twig.md)
|
|
|
57
57
|
fs.createReadStream(`${__dirname}/bookstore.xml`).pipe(parser)
|
|
58
58
|
|
|
59
59
|
// Output -> <bookstore> finished after 48 lines
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// Or use a Parser object instead of a Stream - works only with 'expat'!
|
|
63
|
-
const parser = twig.createParser({ tag: twig.Root, function: rootHandler }, { method: 'expat' })
|
|
64
|
-
parser.write('<html><head><title>Hello World</title></head><body><p>Foobar</p></body></html>');
|
|
65
|
-
|
|
66
|
-
// Output -> xml finished after 1 lines
|
|
67
60
|
```
|
|
68
61
|
|
|
69
62
|
If you prefer [events](https://nodejs.org/api/events.html), then use `event` property instead of `function` in handler declaration:
|
package/package.json
CHANGED
package/twig.js
CHANGED
|
@@ -39,7 +39,8 @@ let current;
|
|
|
39
39
|
* Other parsers I had a look at:
|
|
40
40
|
* {@link https://www.npmjs.com/package/sax-wasm|sax-wasm}: not a 'stream.Writable'
|
|
41
41
|
* {@link https://www.npmjs.com/package/@rubensworks/saxes|saxes}: not a 'stream.Writable'
|
|
42
|
-
* {@link https://www.npmjs.com/package/node-xml-stream|node-xml-stream}:
|
|
42
|
+
* {@link https://www.npmjs.com/package/node-xml-stream|node-xml-stream}: Lacks comment and processinginstruction and maybe self closing tags
|
|
43
|
+
* {@link https://www.npmjs.com/package/node-xml-stream-parser|node-xml-stream-parser}: Lacks comment and processinginstruction
|
|
43
44
|
* {@link https://www.npmjs.com/package/saxes-stream|saxes-stream}: not a 'stream.Writable'
|
|
44
45
|
* {@link https://www.npmjs.com/package/xml-streamer|xml-streamer}: based on 'node-expat', does not add any benefit
|
|
45
46
|
*/
|
|
@@ -414,7 +415,7 @@ function onStart(binds, node, attrs) {
|
|
|
414
415
|
if (typeof hndl.tag === 'string' && name === hndl.tag) {
|
|
415
416
|
elt.pin();
|
|
416
417
|
break;
|
|
417
|
-
} else if (
|
|
418
|
+
} else if (Array.isArray(hndl.tag) && hndl.tag.includes(name)) {
|
|
418
419
|
elt.pin();
|
|
419
420
|
break;
|
|
420
421
|
} else if (hndl.tag instanceof RegExp && hndl.tag.test(name)) {
|
|
@@ -470,7 +471,7 @@ function onClose(handler, options, name) {
|
|
|
470
471
|
if (typeof hndl.function === 'function') hndl.function(tree);
|
|
471
472
|
if (typeof hndl.event === 'string') parser.emit(hndl.event, tree);
|
|
472
473
|
purge = false;
|
|
473
|
-
} else if (
|
|
474
|
+
} else if (Array.isArray(hndl.tag) && hndl.tag.includes(name)) {
|
|
474
475
|
if (typeof hndl.function === 'function') hndl.function(current ?? tree);
|
|
475
476
|
if (typeof hndl.event === 'string') parser.emit(hndl.event, current ?? tree);
|
|
476
477
|
purge = false;
|