Closed Emre-Hacilar closed 4 years ago
You need to create a stream writer with your writable stream and pass it to xmlbuilder. For example:
const xmlStructure = {
// xml structure
};
const writableStream = file.createWriteStream();
const writer = builder.streamWriter(writableStream);
builder.create(xmlStructure , { encoding: 'utf-8' }).end(writer);
writableStream.end();
writableStream.on('end', function() {
// do something in the DB
});
Hi oozcitak, thanks for the fast response, your answer did the trick thanks a lot, I guess the missing line of code was to end the writableStream.
But unfortunately, my XML gets generated as on line now, since the builder.end() ignores my pretty true, is there some way I can add it somewhere else or do I just have to pass it differently?
The way I did it is following:
const xml = root.end(writer, { pretty: true });
Try this:
const writer = builder.streamWriter(writableStream, { pretty: true });
Yes that did the trick, thanks a lot for your time and help.
This should also work:
.
.
.
const writer = builder.streamWriter(writableStream);
builder.create(xmlStructure , { encoding: 'utf-8' }).end({ writer: writer, pretty: true });
.
.
.
Hi,
I saw in the wiki, that the xmlbuilder provides a build in streamwriter, and wanted to use this for my project. I tried some stuff but unfortunatly didn't get it to work.
Here is a example code of my project, where I'd like to add the build in streamwriter: