oozcitak / xmlbuilder2

An XML builder for node.js
362 stars 35 forks source link

Allow two XML elements to be in the same line (maybe with a space between them) #144

Open drthoben opened 2 years ago

drthoben commented 2 years ago

Is your feature request related to a problem? Please describe. I'm using xmlbuilder2 to generate an XML file, which I'd like to import in InDesign. In order to have two XML elements in the same line in InDesign, I need the two XML tags to appear in the same line with a space between them.

The XML would look something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Template>
<friends>
<friend>
<friend_info>
<first_name>Peter</first_name> <last_name>Gabriel</last_name>
<date_of_birth>1970-01-01</date_of_birth>
</friend_info>
</friend>
</friends>
</Template>

Describe the solution you'd like It'll be nice to have some chainable method to disable or change newline for the current element, so that the call would look something like this:

const friendEle = root.ele('friend');
const infoEle = friendEle('friend_info');

infoEle.ele('first_name').txt('Peter').options({ newline: ' ' });
infoEle.ele('last_name').txt('Gabriel');

Describe alternatives you've considered I'm also considering hooking into the callback writer to detect certain tags and if they appear, I remove that newline. But I haven't really found a way to do so.