xml quick export

This commit is contained in:
Jan Prochazka
2022-02-17 17:06:28 +01:00
parent 256f97ad42
commit f8da3c3476
2 changed files with 19 additions and 3 deletions

View File

@@ -21,16 +21,17 @@ function escapeXml(value) {
class StringifyStream extends stream.Transform {
constructor({ itemElementName, rootElementName }) {
super({ objectMode: true });
this.itemElementName = itemElementName;
this.rootElementName = rootElementName;
this.itemElementName = itemElementName || 'row';
this.rootElementName = rootElementName || 'root';
this.startElement(this.rootElementName);
this.push('\n');
}
startElement(element) {
this.push('<');
this.push(element);
this.push('>\n');
this.push('>');
}
endElement(element) {
@@ -47,6 +48,7 @@ class StringifyStream extends stream.Transform {
_transform(chunk, encoding, done) {
this.startElement(this.itemElementName);
this.push('\n');
for (const key of Object.keys(chunk)) {
this.elementValue(key, chunk[key]);
}