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

@@ -31,7 +31,7 @@
"prepublishOnly": "yarn build"
},
"devDependencies": {
"node-xml-stream": "^1.0.2",
"node-xml-stream-parser": "^1.0.12",
"dbgate-plugin-tools": "^1.0.7",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11"

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) {

View File

@@ -7607,10 +7607,10 @@ node-ssh-forward@^0.7.2:
debug "^4.1.1"
ssh2 "^0.8.9"
node-xml-stream@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/node-xml-stream/-/node-xml-stream-1.0.2.tgz#7aa510f39ab125cc420e60a302f49147e80b000f"
integrity sha512-W4LzsKQ1x3TldQQmXZfM/JO+3SPp+zzvA2Nf82chE7vXnZy7LqHjIqQe9yDUw58g2fTOaJo+DlPnIDfmozgsuw==
node-xml-stream-parser@^1.0.12:
version "1.0.12"
resolved "https://registry.yarnpkg.com/node-xml-stream-parser/-/node-xml-stream-parser-1.0.12.tgz#2d97cc91147bbcdffa0a89cf7dfcc129db2aa789"
integrity sha512-qfUiDv1F6OMSltv2/ay32q7fp995OrA3TmEdlwFcxEjAQPiEAH+qi3jAh0QjOTXNbdLa5hoYhuBPCiylllGfjg==
nodemon@^2.0.2:
version "2.0.2"