xml-twig 1.9.4 → 1.10.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 +4 -0
- package/doc/twig.md +2 -2
- package/package.json +1 -1
- package/twig.js +19 -10
package/README.md
CHANGED
|
@@ -57,6 +57,10 @@ API Documentation: see [Twig](./doc/twig.md)
|
|
|
57
57
|
const parser = twig.createParser({ tag: twig.Root, function: rootHandler }, { method: 'sax' })
|
|
58
58
|
fs.createReadStream(`${__dirname}/bookstore.xml`).pipe(parser)
|
|
59
59
|
|
|
60
|
+
parser.on('error', function (err) {
|
|
61
|
+
console.error(err);
|
|
62
|
+
});
|
|
63
|
+
|
|
60
64
|
// Output -> <bookstore> finished after 48 lines
|
|
61
65
|
```
|
|
62
66
|
|
package/doc/twig.md
CHANGED
|
@@ -1528,7 +1528,7 @@ Generic error for unsupported condition
|
|
|
1528
1528
|
|
|
1529
1529
|
## SAX
|
|
1530
1530
|
**Kind**: global constant
|
|
1531
|
-
**Version:**: 1.
|
|
1531
|
+
**Version:**: 1.10.0
|
|
1532
1532
|
**Author:**: Wernfried Domscheit
|
|
1533
1533
|
**Copyright:**: Copyright (c) 2025 Wernfried Domscheit. All rights reserved.
|
|
1534
1534
|
**Website:**: https://www.npmjs.com/package/xml-twig
|
|
@@ -1600,7 +1600,7 @@ Optional settings for the Twig parser
|
|
|
1600
1600
|
| method | <code>'sax'</code> \| <code>'expat'</code> | The underlying parser. Either `'sax'`, `'expat'`. |
|
|
1601
1601
|
| xmlns | <code>boolean</code> | If `true`, then namespaces are accessible by `namespace` property. |
|
|
1602
1602
|
| trim | <code>boolean</code> | If `true`, then turn any whitespace into a single space. Text and comments are trimmed. |
|
|
1603
|
-
| resumeAfterError | <code>boolean</code> | If `true` then parser continues reading after an error
|
|
1603
|
+
| resumeAfterError | <code>boolean</code> | If `true` then parser continues reading after an error.<br> Only relevant for `sax`, `expat` always terminates on error. |
|
|
1604
1604
|
| partial | <code>boolean</code> | If `true` then unhandled elements are purged. |
|
|
1605
1605
|
| file | <code>string</code> | Optional. The name of file to be parsed. Just used for information and logging purpose. |
|
|
1606
1606
|
|
package/package.json
CHANGED
package/twig.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @version: 1.
|
|
2
|
+
* @version: 1.10.0
|
|
3
3
|
* @author: Wernfried Domscheit
|
|
4
4
|
* @copyright: Copyright (c) 2025 Wernfried Domscheit. All rights reserved.
|
|
5
5
|
* @website: https://www.npmjs.com/package/xml-twig
|
|
@@ -65,7 +65,8 @@ const Any = new AnyHandler();
|
|
|
65
65
|
* @property {'sax' | 'expat'} method - The underlying parser. Either `'sax'`, `'expat'`.
|
|
66
66
|
* @property {boolean} xmlns - If `true`, then namespaces are accessible by `namespace` property.
|
|
67
67
|
* @property {boolean} trim - If `true`, then turn any whitespace into a single space. Text and comments are trimmed.
|
|
68
|
-
* @property {boolean} resumeAfterError - If `true` then parser continues reading after an error
|
|
68
|
+
* @property {boolean} resumeAfterError - If `true` then parser continues reading after an error.<br>
|
|
69
|
+
* Only relevant for `sax`, `expat` always terminates on error.
|
|
69
70
|
* @property {boolean} partial - If `true` then unhandled elements are purged.
|
|
70
71
|
* @property {string} [file - Optional. The name of file to be parsed. Just used for information and logging purpose.
|
|
71
72
|
* @example { method: 'expat', xmlns: true }
|
|
@@ -222,6 +223,15 @@ function createParser(handler, options = {}) {
|
|
|
222
223
|
parser.emit("close");
|
|
223
224
|
});
|
|
224
225
|
|
|
226
|
+
parser.on('error', function (err) {
|
|
227
|
+
if (options.resumeAfterError) {
|
|
228
|
+
parser._parser.error = null;
|
|
229
|
+
parser._parser.resume();
|
|
230
|
+
} else {
|
|
231
|
+
parser._parser.close();
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
225
235
|
} else if (EXPAT.includes(options.method)) {
|
|
226
236
|
parser = require("node-expat").createParser();
|
|
227
237
|
Object.defineProperty(parser, 'currentLine', {
|
|
@@ -262,6 +272,13 @@ function createParser(handler, options = {}) {
|
|
|
262
272
|
parser.emit("finish");
|
|
263
273
|
});
|
|
264
274
|
|
|
275
|
+
parser.on('error', function (err) {
|
|
276
|
+
// convert 'err' string into Error object
|
|
277
|
+
if (typeof err === 'string')
|
|
278
|
+
parser.emit('error', Error(`${err}\nLine: ${parser.currentLine}\nColumn: ${parser.currentColumn}`))
|
|
279
|
+
// resume not supported
|
|
280
|
+
});
|
|
281
|
+
|
|
265
282
|
} else {
|
|
266
283
|
throw new UnsupportedParser(options.method);
|
|
267
284
|
}
|
|
@@ -315,14 +332,6 @@ function createParser(handler, options = {}) {
|
|
|
315
332
|
}
|
|
316
333
|
});
|
|
317
334
|
|
|
318
|
-
parser.on('error', function (err) {
|
|
319
|
-
console.error(`error at line [${parser.currentLine}], column [${parser.currentColumn}]`, err);
|
|
320
|
-
if (options.resumeAfterError) {
|
|
321
|
-
parser.underlyingParser.error = null;
|
|
322
|
-
parser.underlyingParser.resume();
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
|
|
326
335
|
return parser;
|
|
327
336
|
}
|
|
328
337
|
|