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