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:

Eclipse has a really great formatting feature that allows you to use Java code to format what Eclipse shows you when looking at variables. To use it for Dom4j objects, do the following:

  • 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:
  • Click OK. You will now see a more readable format for your Dom4j objects: