oozcitak / xmlbuilder-js

An XML builder for node.js
MIT License
919 stars 108 forks source link

writer function overrides no longer functional from end(options)? #254

Open btsimonh opened 2 years ago

btsimonh commented 2 years ago

using xmlbuilder via xml2js, this file: https://github.com/Leonidas-from-XIV/node-xml2js/blob/master/src/builder.coffee calls end with writer options.

In previous versions, writer options could look like:

{
            'pretty': true,
            'indent': ' ',
            'newline': '\n',
            writer: { element: newElement, /*endline: newEndline*/ },
}

but the current version (and from version 11?) discards the 'writer' part of the options in 'filterOptions' (in XMLWriterBase).

the wiki: https://github.com/oozcitak/xmlbuilder-js/wiki still states the functions can be overridden.

Is there a way to override these functions?

br, Simon

stefanocudini commented 2 years ago

@oozcitak also for me, this method not work like as docs

btsimonh commented 2 years ago

my workaround was to replace the output function in xml2js, ending:

        let xmlbuilderoptions = {
          pretty: defaultPretty,
          indent: " ",
          newline: defaultNewline,
          writer: { element: newElement /*endline: newEndline*/ },
          //async: false,
        };
        let writer = xmlbuilder.stringWriter(xmlbuilderoptions);
        let doc = render(rootElement, rootObj);
        return doc.end(writer);

basically - passing in a created stringWriter into which the options were inserted at creation, rather than passing the options into doc.end().

stefanocudini commented 2 years ago

please update the documentation :( it's really hard to understand how to use a custom writer right now this line is not specified: let writer = xmlbuilder.stringWriter(xmlbuilderoptions);

DawnLHM commented 1 year ago

I just discovered what seems to be the issue - "pretty" has changed to "prettyPrint".

So ele.end({ prettyPrint: true }) works!

Thanks to IntelliJ's pop-up documentation with links for leading me to that!