50

I would like to change the way Eclipse formats XML files. For example, if I have in pom.xml file a section as follows:

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

After ctrl+shift+f it will look like:

    <dependency>
        <groupId>
            junit
        </groupId>
        <artifactId>
            junit
        </artifactId>
        <version>
            3.8.1
        </version>
        <scope>
            test
        </scope>
    </dependency>

I prefer the first version, so how to configure Eclipse to format XML files to look like that?

tputkonen
  • 5,579
  • 16
  • 60
  • 88

3 Answers3

43

Window -> Preferences, then XML -> XML Files -> Editor. There is a search box above the preferences tree, very useful when you want to find where something is configured.

Note that it may be some other editor is used, e.g. if you're editing a build.xml file and have the Ant integration. In this specific case you'd set up the formatting at Window -> Preferences, Ant -> Editor -> Formatter. In similiar cases you need to search for the corresponding options for that editor yourself.

zb226
  • 9,586
  • 6
  • 49
  • 79
unbeli
  • 29,501
  • 5
  • 55
  • 57
  • 5
    I have examined to settings in the window you mentioned, but there doesn't seem to be a setting affecting the formatting in question. – tputkonen May 31 '10 at 12:13
  • 4
    1- try increasing the line length, maybe it simply does not fit. 2- do you have any plugin that handles POM files in eclipse? m2eclipse, etc.? – unbeli May 31 '10 at 12:24
  • 10
    Thanks for the tip. Aptana XML editor was used for editing the file, and it screwed up the formatting. Right click on pom.xml -> open with -> XML editor did the trick – tputkonen May 31 '10 at 12:54
  • 4
    I had same problem. It had opened with "Android Common XML Editor", opening with "Maven POM Editor" worked well for me. – Stan Kurdziel Jul 31 '12 at 01:34
  • I had the same problem after installing ADT (Android for Eclipse). I changed it to open with "Spring Config Editor" and not only regained the formating I wanted but also Spring autocompletion of bean properties. Thanks! – yoavram Aug 17 '12 at 07:16
14

I have solution so you should go to Preferences->Andriod->Editors and disable first line "Format XML files using the standard Android XML..." that is the solution. It is connected with instaling ADT plugin I guess.

RMachnik
  • 3,598
  • 1
  • 34
  • 51
4

TRY this

Window->Preferences->XML->XML Files->Editor ... Under Formatting-> Line width

Increase the width value(say 150), until you've desired Tag format

ManishS
  • 627
  • 2
  • 11
  • 21