Created
March 28, 2012 16:26
-
-
Save edalquist/2227971 to your computer and use it in GitHub Desktop.
Eclipse XML Detail Formatter
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
When dealing with XML variables (Document, Node, Element) in the debug view of Eclipse | |
it can be handy to see the actual XML instead of the object model. Eclipse's Detail | |
Formatter feature makes this possible. | |
* Right click on the xml object in question | |
* Select "New Detail Formatter" | |
* Paste the code below into the Detail Formatter Code Snippet | |
* Enjoy! |
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
if (this == null) return null; | |
javax.xml.transform.TransformerFactory tf = javax.xml.transform.TransformerFactory.newInstance(); | |
javax.xml.transform.Transformer transformer = tf.newTransformer(); | |
transformer.setOutputProperty( javax.xml.transform.OutputKeys.METHOD, "xml"); | |
transformer.setOutputProperty("encoding", "UTF-8"); | |
transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT,"yes"); | |
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3" ); | |
javax.xml.transform.dom.DOMSource source = new javax.xml.transform.dom.DOMSource(this); | |
if (source == null) return "Corrupted XML document: " + this.toString(); | |
java.io.StringWriter os = new java.io.StringWriter(); | |
javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(os); | |
transformer.transform(source,result); | |
return os.toString (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For dealing with a jdom Document, I've modified your Detail Formatter: