Created
January 21, 2013 10:55
-
-
Save aphexmunky/4585254 to your computer and use it in GitHub Desktop.
JDom XML pretty print
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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