oozcitak/xmlbuilder2

XML prolog does not contain encoding

muratmat opened this issue · 3 comments

The following code:

const xml_builder = require('xmlbuilder2');
const xml = xml_builder.create(mycontent, { version: '1.0', encoding: 'UTF-8', standalone: true }).end({ prettyPrint: true });

always produce the following xml prolog:

<?xml version="1.0"?>

without the encoding. How can I obtain the correct xml prolog?

<?xml version="1.0" encoding="UTF-8" ?>

Many thanks in advance.

I've also tried a multi step approach, but the bug is still there:

const xml_builder = require('xmlbuilder2');
let xml_doc = xml_builder.create(...)
xml_doc.dec('1.0', 'UTF-8', true);
const xml = xml_doc.end({ prettyPrint: true });

The prolog still messes the encoding="UTF-8" part.
Could you please fix this bug? Many thanks in advance.

Your argument order is wrong. Instead of:

create(mycontent, { version: '1.0', encoding: 'UTF-8', standalone: true })

you should have:

create({ version: '1.0', encoding: 'UTF-8', standalone: true }, mycontent)

Please see: https://oozcitak.github.io/xmlbuilder2/builder-functions.html#create

Many thanks for your help, now it works like a charm.