Debugging XML Objects
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!
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 ();Â
Add Feedback content box here.....