Search code examples
javaxmleclipsepretty-print

Pretty Print XML in Eclipse Console from Display View


I have an object that I can get a String from during debugging. That string is valid XML, but it's "half pretty" (let's say it's just a 6 out of 10 on the "XML Hotness Scale") in that it has each node on its own line, but the text isn't indented.

I was wondering if anyone knew of an easy way to use the tools available to the Display view in Eclipse so that when I write that string to the Console view it's properly indented?

Or I can write a thin static method on my own to do it if someone can guide me as to how to make that method available for use in the Display view.

Thanks in advance!

-Matt


Solution

  • Based on what you are saying you want a quick scrapbook to format XML files. Unfortunately the Display view or the Scrapbook Page file do not support code formatting. The quickest way is to have on the side (or on your Sandbox project) an XML file where you would paste your unformatted XML, then you hit Ctrl + A to select everything and Ctrl + Shift + F to beautify your XML.

    If you want to do that programatically have a look at this answer.