Pretty-printing output from javax.xml.transform.Transformer with only standard java api (Indentation and Doctype positioning)

The missing part is the amount to indent. You can set the indentation and indent amount as follow: transformer.setOutputProperty(OutputKeys.INDENT, “yes”); transformer.setOutputProperty(“{http://xml.apache.org/xslt}indent-amount”, “2”); transformer.transform(xmlInput, xmlOutput);

How to pretty print variables

If your goal is to avoid importing a third-party package, your other option is to use json.MarshalIndent: x := map[string]interface{}{“a”: 1, “b”: 2} b, err := json.MarshalIndent(x, “”, ” “) if err != nil { fmt.Println(“error:”, err) } fmt.Print(string(b)) Output: { “a”: 1, “b”: 2 } Working sample: http://play.golang.org/p/SNdn7DsBjy

How can I print a list of elements separated by commas?

Use an infix_iterator: // infix_iterator.h // // Lifted from Jerry Coffin’s ‘s prefix_ostream_iterator #if !defined(INFIX_ITERATOR_H_) #define INFIX_ITERATOR_H_ #include <ostream> #include <iterator> template <class T, class charT=char, class traits=std::char_traits<charT> > class infix_ostream_iterator : public std::iterator<std::output_iterator_tag,void,void,void,void> { std::basic_ostream<charT,traits> *os; charT const* delimiter; bool first_elem; public: typedef charT char_type; typedef traits traits_type; typedef std::basic_ostream<charT,traits> ostream_type; infix_ostream_iterator(ostream_type& s) : … Read more

How do I get Python’s ElementTree to pretty print to an XML file?

Whatever your XML string is, you can write it to the file of your choice by opening a file for writing and writing the string to the file. from xml.dom import minidom xmlstr = minidom.parseString(ET.tostring(root)).toprettyxml(indent=” “) with open(“New_Database.xml”, “w”) as f: f.write(xmlstr) There is one possible complication, especially in Python 2, which is both less … Read more

A way to pretty print a C# object

If you use Json then I would suggest using Newtonsofts Json library and then you can output the entire object in Json notation and it will format it with spacing and line breaks. we have used this to display complex objects easily for debug purposes: var jsonString = JsonConvert.SerializeObject( complexObject, Formatting.Indented, new JsonConverter[] {new StringEnumConverter()}); … Read more