Skip to content

Instantly share code, notes, and snippets.

@aphexmunky
Created January 21, 2013 10:55
Show Gist options
  • Save aphexmunky/4585254 to your computer and use it in GitHub Desktop.
Save aphexmunky/4585254 to your computer and use it in GitHub Desktop.
JDom XML pretty print
package com.thehutgroup.sherlock.domain;
import java.io.StringReader;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
public class Snippet {
public static void main(String[] args) throws Exception {
new Snippet().sampleCode();
}
private void sampleCode() throws Exception {
StringReader xmlReader = new StringReader("<test><first>level 1</first><second><inner>level 2</inner></second></test>");
Document dom = new SAXBuilder().build(xmlReader);
XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
xmlOutputter.output(dom, System.out);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment