August 20, 2009

Eclipse XML DetailFormatter

Having had to work with XML a lot for a current project I was tired of drilling down the DOM objects in Eclipse's debugger so I went looking on the net for an Eclipse debug detail formatter and found one here:

I do had to remove a few lines to get it to work so here is my version, enjoy formatted XML tags from a DOM tree:
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("{}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(); os = new; result = new;

return os.toString ();