improved xml importer

This commit is contained in:
Jan Prochazka
2022-02-03 09:34:17 +01:00
parent 354f50d43c
commit 8ee828dd21
3 changed files with 17 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
const fs = require('fs');
const stream = require('stream');
const NodeXmlStream = require('node-xml-stream');
const NodeXmlStream = require('node-xml-stream-parser');
class ParseStream extends stream.Transform {
constructor({ itemElementName }) {
@@ -26,6 +26,17 @@ class ParseStream extends stream.Transform {
if (this.stack.length >= 2) {
this.stack[this.stack.length - 2].nodes[this.stack[this.stack.length - 1].name] = text;
}
if (this.stack.length >= 1) {
this.stack[this.stack.length - 1].nodes.$text = text;
}
});
this.parser.on('cdata', (text) => {
if (this.stack.length >= 2) {
this.stack[this.stack.length - 2].nodes[this.stack[this.stack.length - 1].name] = text;
}
if (this.stack.length >= 1) {
this.stack[this.stack.length - 1].nodes.$text = text;
}
});
this.parser.on('closetag', (name, attrs) => {
if (name == element) {