Вопрос

I have some XML that looks like this (after pasting a new Maven dependency):

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.6.0.Final</version>
    </dependency>
    <dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.0</version>
</dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.11</version>
    </dependency>

When I select the text and select Source → Format (Ctrl+Shift+F by default), I expect it to end up looking like this:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.6.0.Final</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <version>1.3.0</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.11</version>
    </dependency>

But instead, it looks like this:

    </dependency><dependency>

        <groupId>
org.hibernate
        </groupId>

        <artifactId>
hibernate-entitymanager
        </artifactId>

        <version>
3.6.0.Final
        </version>
    </dependency>

    <dependency>

        <groupId>
net.sourceforge.jtds
        </groupId>

        <artifactId>
jtds
        </artifactId>

        <version>
1.3.0
        </version>

Yuck!

If I don't select any text and try to just format the entire file, it does the same thing: put newline characters before all text (character data).

I've played with settings in Window → Preferences → XML → XML Files → Editor → Formatting, but none of them seem to fix this. There's certainly no 'Insert annoying newline characters before text' checkbox ticked!

Any ideas for how to fix this? FWIW, formatting Java code works beautifully.

Help → About Eclipse:

Eclipse Java EE IDE for Web Developers.

Version: Indigo Service Release 2
Build id: 20120216-1857

I'm launching Eclipse for Windows from within Cygwin, but not noticing any other CR/LF-related issues. Still, I tried switching the file from unix- to DOS-style linefeeds, but that made no difference.

Это было полезно?

Решение 2

Check that you're using the XML Editor; you're using its preference page and those preferences may not applicable to other editors.

Другие советы

I was experiencing these issue due to the line width setting under XML > XML Files > Editor. Increased to 200 and the line breaks went away. enter image description here

Note: Some developers might discourage you from increasing this to +80 incase your code is ever printed or viewed on a mobile device. It is also good to keep in mind, side-by-side and three-way code compare tools. In this situation, increasing the line width setting could make legibility difficult.

Edited thanks to @MichaelScheper 's comment

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top