mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 05:36:01 +00:00
xml feed reader - auto detect item name
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import HorizontalSplitter from '../elements/HorizontalSplitter.svelte';
|
||||
import LargeButton from '../elements/LargeButton.svelte';
|
||||
import LoadingInfo from '../elements/LoadingInfo.svelte';
|
||||
import VerticalSplitter from '../elements/VerticalSplitter.svelte';
|
||||
|
||||
import FormProvider from '../forms/FormProvider.svelte';
|
||||
@@ -146,6 +147,10 @@
|
||||
<HorizontalSplitter initialValue="70%">
|
||||
<div class="content" slot="1">
|
||||
<ImportExportConfigurator {uploadedFile} {openedFile} {previewReaderStore} />
|
||||
|
||||
{#if busy}
|
||||
<LoadingInfo wrapper message="Processing import/export ..." />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<svelte:fragment slot="2">
|
||||
|
||||
@@ -5,10 +5,21 @@ const NodeXmlStream = require('node-xml-stream');
|
||||
class ParseStream extends stream.Transform {
|
||||
constructor({ itemElementName }) {
|
||||
super({ objectMode: true });
|
||||
|
||||
let element = itemElementName;
|
||||
|
||||
this.push({
|
||||
__isStreamHeader: true,
|
||||
__isDynamicStructure: true,
|
||||
});
|
||||
|
||||
this.rowsWritten = 0;
|
||||
this.parser = new NodeXmlStream();
|
||||
this.stack = [];
|
||||
this.parser.on('opentag', (name, attrs) => {
|
||||
if (!element && this.stack.length == 1) {
|
||||
element = name;
|
||||
}
|
||||
this.stack.push({ name, attrs, nodes: {} });
|
||||
});
|
||||
this.parser.on('text', (text) => {
|
||||
@@ -17,9 +28,12 @@ class ParseStream extends stream.Transform {
|
||||
}
|
||||
});
|
||||
this.parser.on('closetag', (name, attrs) => {
|
||||
if (name == itemElementName) {
|
||||
this.rowsWritten += 1;
|
||||
this.push({ ...this.stack[this.stack.length - 1].attrs, ...this.stack[this.stack.length - 1].nodes });
|
||||
if (name == element) {
|
||||
const obj = { ...this.stack[this.stack.length - 1].attrs, ...this.stack[this.stack.length - 1].nodes };
|
||||
if (Object.keys(obj).length > 0) {
|
||||
this.rowsWritten += 1;
|
||||
this.push(obj);
|
||||
}
|
||||
}
|
||||
this.stack.splice(-1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user