Eric Bergman-Terrell's Blog

Node.js Programming Tip: How to Pretty-Print XML
September 14, 2015

This website's XML Pretty-Print utility uses the following code to convert JSON text into ready-to-read XML. Obviously, pretty-data is doing all the work. The second argument to the xml function specifies whether or not to retain XML comments.

var pd = require('pretty-data');

exports.prettyPrint = function(source) {
    return pd.pd.xml(source, true);
};
Pretty Print XML

I am pretty and well-formed!

Keywords: Node.js, node, Express, JavaScript, XML, pretty print, formatting, pretty-data, comments

Reader Comments

Comment on this Blog Post

Recent Posts

TitleDate
Get JetBrains IDEs to Remember Subversion (SVN) CredentialsNovember 3, 2026
Converting a Thinkpad from Windows 11 to Linux MintOctober 29, 2026
Raspberry Pi Camera Trap and Animal Detection ProgramAugust 29, 2026
Python Tip: Fix Incorrect Orientation of Digital PhotosAugust 8, 2026
EBT Weather is now available for Windows and LinuxMay 30, 2026
Node.js + Express: How to Block Requests by User-Agent HeadersJanuary 7, 2026
Vault 3 is Now Available for Windows on ARM Machines!December 13, 2025