Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
btsimonh opened this issue Aug 16, 2022 · 4 comments
Open

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

btsimonh opened this issue Aug 16, 2022 · 4 comments

Comments

@btsimonh
Copy link

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
Copy link

stefanocudini commented Sep 5, 2022

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

@btsimonh
Copy link
Author

btsimonh commented Sep 5, 2022

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
Copy link

stefanocudini commented Sep 6, 2022

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
Copy link

DawnLHM commented Jan 17, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants