eclipse xml format

以前很喜欢在Eclipse中使用CTRL+ALT+F来进行自动排版.不过今天发现以后要绝对慎用这项功能,尤其是在xml和html中,尽量不要使用..因为今天发现,本来运行得很好的配置文件,只要一自动排版,就会报出一些莫名其妙的错误,而且这种错误是你检查配置检查不出来的,因为配置看起来根本就没变!!
猜测是由于在xml的entity中加了空格或者换行符的缘故.

 

 

 
有同感,在格式话的时候会加入空格,而很难检查出问题。
像数据库的连接地址,要保证中间没有空格,但格式化后会加入空格。导致数据库连接出错

 

 

eclipse  中的 code format 中的问题看来不只我一个人遇到,特别是在xml文件中format代码。

 

一般的解决办法有如下途径:

 

eclipse code format设置

eclipse code format设置

上面仅仅是针对Eclipse基本的Editor设置。对于Java/HTML/Ant等扩展编辑器,你还不得不单独去设定
      * Preference:
       1). For Java: sets java code style in eclipse
           windows->preferences->java->Code style->Formatter
           add a new profile , for more detail, test it in eclipse please
       2). For Ant: sets build.xml in eclipse
           windows->preferences->Ant>Editor->Formatter
           uncheck [Use tab character instead of spaces] option.
       3). For Html:
           windows->preferences->Web and XML->HTML Files->HTML Source
           select "Indent using tabs" and set space =2
       4). For XML:
           windows->preferences->Web and XML->XML Files->XML Source
           select "Indent using tabs" and set space =2
       5). For Properties
    3). 如何配置jsp,properties等文件默认使用UTF-8编码创建或者阅读?
     (Eclipse3.2+) Windows->General->Content Types下选择指定的扩展名,然后说明相应的编码,然后Update.
    4). 转换存在文件的回车换行格式

 

 

我在xml中遇到这种问题,我改到的地方只是在windows->preferences->myeclipse->files and editors->xml->xml source 下面的formatting栏中将line width 设置成172 ,默认是72.

我想,可能是因为line width 过小,导至在fomat时自动把xml 标签split掉,然后又加了一些多余的空格,因而改变了xml 实际内容。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值