This asset works beautifully!
Having said that, it converts self-closing tags to to separate tags: <street/> becomes <street></street>.
Can I configure it a way that it shows the self-closing tag as is?
Thanks,
Rogier
Hi Rogier,
Prettify typically parses the XML as a DOM, then renders it out with explicit open/close tags for consistency, which inherently expands self‑closing tags.
After prettifying, you can run a simple replacement to convert any empty tags back into self‑closing form. For example, with JavaScript
formattedXml = formattedXml.replace(/<(\w+)><\/\1>/g, '<$1/>');
Use this transformation in an OutSystems action or client script right after calling XML Prettify. This is quick, easy, and works well if your XML tags are simple alphanumeric names.
If you don’t mind the minor risk of regex edge cases, go for above option it's simple and effective. If your XML needs are complex (namespaces, deeper structure, attribute-rich empty tags), consider customizing the library.
Thanks!
In the meantime I found a way to get this done by making a simple change to the createNodeElement() function.
This funtion is already aware whether an XML node contains child nodes or inner text. If not, instead of outputting a full closing tag I just made the opening tag self closing. This was all and it covers all situations.
if (node.childNodes.length > 0) {
// finish the XML tag with angle bracket to be the opening tag, to be followed by child nodes or inner text
const XMLOpeningTagEnd = document.createElement('span');
XMLOpeningTagEnd.classList.add('xml-tag');
XMLOpeningTagEnd.textContent = '>';
element.appendChild(XMLOpeningTagEnd);
// add child nodes recursively
const content = document.createElement('div');
content.classList.add('xml-content');
for (const child of node.childNodes) {
content.appendChild(createNodeElement(child));
}
element.appendChild(content);
const XMLClosingTag = document.createElement('span');
XMLClosingTag.classList.add('xml-tag');
XMLClosingTag.textContent = ``;
element.appendChild(XMLClosingTag);
} else {
// no child nodes or innt text: Make XML tag self closing
const XMLOpeningTagSelfClosing = document.createElement('span');
XMLOpeningTagSelfClosing.classList.add('xml-tag');
XMLOpeningTagSelfClosing.textContent = '/>';
element.appendChild(XMLOpeningTagSelfClosing);