How can I pretty-print XML source using VB6 and MSXML?

After months of research I’ve come up with this. Public Function PrettyPrintXML(XML As String) As String Dim Reader As New SAXXMLReader60 Dim Writer As New MXXMLWriter60 Writer.indent = True Writer.standalone = False Writer.omitXMLDeclaration = False Writer.encoding = “utf-8” Set Reader.contentHandler = Writer Set Reader.dtdHandler = Writer Set Reader.errorHandler = Writer Call Reader.putProperty(“http://xml.org/sax/properties/declaration-handler”, _ Writer) Call … Read more

How do I pretty-print HTML with Nokogiri?

The answer by @mislav is somewhat wrong. Nokogiri does support pretty-printing if you: Parse the document as XML Instruct Nokogiri to ignore whitespace-only nodes (“blanks”) during parsing Use to_xhtml or to_xml to specify pretty-printing parameters In action: html=”<section> <h1>Main Section 1</h1><p>Intro</p> <section> <h2>Subhead 1.1</h2><p>Meat</p><p>MOAR MEAT</p> </section><section> <h2>Subhead 1.2</h2><p>Meat</p> </section></section>” require ‘nokogiri’ doc = Nokogiri::XML(html,&:noblanks) puts … Read more

NumPy: Pretty print tabular data

I seem to be having good output with prettytable: from prettytable import PrettyTable x = PrettyTable(dat.dtype.names) for row in dat: x.add_row(row) # Change some column alignments; default was ‘c’ x.align[‘column_one’] = ‘r’ x.align[‘col_two’] = ‘r’ x.align[‘column_3’] = ‘l’ And the output is not bad. There is even a border switch, among a few other options: … Read more

Python pretty XML printer with lxml

For me, this issue was not solved until I noticed this little tidbit here: http://lxml.de/FAQ.html#why-doesn-t-the-pretty-print-option-reformat-my-xml-output Short version: Read in the file with this command: >>> parser = etree.XMLParser(remove_blank_text=True) >>> tree = etree.parse(filename, parser) That will “reset” the already existing indentation, allowing the output to generate it’s own indentation correctly. Then pretty_print as normal: >>> tree.write(<output_file_name>, … Read more

How can I get Express to output nicely formatted HTML?

In your main app.js or what is in it’s place: Express 4.x if (app.get(‘env’) === ‘development’) { app.locals.pretty = true; } Express 3.x app.configure(‘development’, function(){ app.use(express.errorHandler()); app.locals.pretty = true; }); Express 2.x app.configure(‘development’, function(){ app.use(express.errorHandler()); app.set(‘view options’, { pretty: true }); }); I put the pretty print in development because you’ll want more efficiency with … Read more

How can I beautify JavaScript code using Command Line?

First, pick your favorite Javascript based Pretty Print/Beautifier. I prefer the one at http://jsbeautifier.org/, because it’s what I found first. Downloads its file https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js Second, download and install The Mozilla group’s Java based Javascript engine, Rhino. “Install” is a little bit misleading; Download the zip file, extract everything, place js.jar in your Java classpath (or … Read more