18

Is it possible to somehow auto-format when saving XML files in Eclipse?

I know it's possible to do it for Java files, but I would like it to happen for XML files as well.

Specifically, I'm using and loving the auto format feature for XML files while developing for Android, as Android is quite heavy on using XML files.

Community
  • 1
  • 1
Artem Russakovskii
  • 21,516
  • 18
  • 92
  • 115

4 Answers4

6

For eclipse auto-format try Ctrl+Shift+F

Anthony Giorgio
  • 1,844
  • 1
  • 15
  • 17
UmAnusorn
  • 10,420
  • 10
  • 72
  • 100
  • 2
    That's not auto-format on save, that's just format on demand. The question has been answered already, thanks. – Artem Russakovskii Jan 19 '12 at 17:17
  • Well, I knew that one already, but it would be great if there was an option to apply the auto-format every time the XML file is saved, like Eclipse can do for Java files. – Alef Mar 24 '23 at 13:30
5

I'm going to answer my own question using my own article about the fix that's about to be rolled out to ADT: http://www.androidpolice.com/2010/11/09/for-android-developers-next-version-of-eclipse-adt-to-include-auto-formatting-of-xml/

Update: since r14, ADT can now finally do this. http://tools.android.com/recent/xmlformatter

Artem Russakovskii
  • 21,516
  • 18
  • 92
  • 115
  • For an even faster response, just check "format on save" option here: http://tools.android.com/_/rsrc/1313083386935/recent/xmlformatter/format-settings.png – Milton Aug 03 '13 at 13:13
  • 2
    This is great and all for Android.. But this doesn't answer the question of "Formatting XML on save" that does not have android. Any solution for just general XML files? – WORMSS Oct 12 '16 at 15:42
  • Such a shame that this was added with a plugin specifically for ADT rather than a fix for Eclipse as a whole. I don't work on Android, so I'm not going to switch to ADT just for that. – Alef Mar 24 '23 at 13:29
3

It's been requested in WTP (bug 221696), but for now increasing the formatter's quality and speed in general has a higher priority.

nitind
  • 19,089
  • 4
  • 34
  • 43
  • The only thing that comes up for 221696 and wtp on google is http://www.eclipse.org/forums/index.php?t=msg&goto=221696&S=e6f102c17d33af4f02ce5982371ff40e which doesn't seem to be related. Can you provide a link please? – Artem Russakovskii Nov 05 '09 at 16:52
0

Here are a few related Eclipse bugs I found. Please vote for them if auto-save for XML files and project specific XML formatting settings are important to you.

Reto Höhener
  • 5,419
  • 4
  • 39
  • 79