Just the other day, I was griping about the way Eclipse ADT tools dump out XML in long unreadable lines like this:
As with so many things, Eclipse is your friend if you just know how to set it up. As it turns out, Artem Russakovskii of Beer Planet recently wrote an excellent post with instructions for configuring Eclipse to auto-format your XML pleasingly so it will look more like this:
I can do no better than to refer you to the post. In case he moves it or something, the short-and-sweet version is:
- Window -> Preferences -> XML -> XML Files -> Editor
- Source -> Cleanup Document
Making your XML readable means it’s also a lot more writeable. The ADT GUIs for working with resources are very handy, and you might not think you want to write XML by hand, but Eclipse is your friend here, too: it will suggest and auto-complete tags and attributes for you.
Eclipse can suggest and auto-complete allowed tags, attributes, and values for attributes based on the XML schemas supplied by the SDK. If Eclipse isn’t automatically suggesting (or like me, you’ve turned off auto-suggestions because they’re annoying), you can just press Ctrl-Space with your cursor placed where you’d like a suggestion in the document, use the arrow keys to choose a suggestion, and hit Enter to accept one. As you can see above, the suggestions come with at least minimal descriptions to jog your memory. This makes writing XML “by hand” almost completely painless.
