如何配置 Eclipse XML 格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2943350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure Eclipse XML formatting?
提问by tputkonen
I would like to change the way Eclipse formats XML files. For example, if I have in pom.xml file a section as follows:
我想改变 Eclipse 格式化 XML 文件的方式。例如,如果我在 pom.xml 文件中有一个部分,如下所示:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
After ctrl+shift+f it will look like:
在 ctrl+shift+f 之后,它将看起来像:
<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?
我更喜欢第一个版本,那么如何配置 Eclipse 以将 XML 文件格式化成这样呢?
采纳答案by unbeli
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.
窗口 -> 首选项,然后 XML -> XML 文件 -> 编辑器。首选项树上方有一个搜索框,当您想查找配置的位置时非常有用。
Note that it may be some other editor is used, e.g. if you're editing a build.xmlfile 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.
请注意,它可能使用了其他一些编辑器,例如,如果您正在编辑build.xml文件并具有 Ant 集成。在这种特定情况下,您将在 Window -> Preferences, Ant -> Editor -> Formatter 中设置格式。在类似情况下,您需要自己搜索该编辑器的相应选项。
回答by RMachnik
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.
我有解决方案,因此您应该转到首选项-> Andriod-> 编辑器并禁用第一行“使用标准 Android XML 格式化 XML 文件...”,这就是解决方案。我猜它与安装 ADT 插件有关。
回答by ManishS
TRY this
尝试这个
Window->Preferences->XML->XML Files->Editor ... Under Formatting-> Line width
Window->Preferences->XML->XML Files->Editor ...在Formatting-> Line width下
Increase the width value(say 150), until you've desired Tag format
增加宽度值(比如 150),直到你想要标签格式

