Eclipse Tips: Debugging XML

When using dom4j objects in Eclipse, it is sometimes hard to determine what the contents of a particular Document or Element are:

Step into code that uses an Element, Document, etc
  • Open the Variables view, right click on the object, and select “New Detail Formatter”:
  • Enter the following code:
  • java.io.StringWriter sw = new java.io.StringWriter(); 
    org.dom4j.io.OutputFormat format = org.dom4j.io.OutputFormat.createPrettyPrint(); 
    org.dom4j.io.XMLWriter writer = new org.dom4j.io.XMLWriter( sw, format ); 
    writer.write(this); 
    return sw.toString();
    
  • Click OK. You will now see a more readable format for your Dom4j objects: