gpt4 book ai didi

xml - 将 XML 文件中的制表符更改为空格

转载 作者:行者123 更新时间:2023-12-03 09:10:50 24 4
gpt4 key购买 nike

创建许多文件后,我将 Eclipse 配置更改为 use spaces instead of tabs 。它有效:我写的新东西使用空格。但是我昨天写的文件当然仍然有选项卡。我想将它们从制表符转换为空格。

对于 Java 文件,这很简单:打开文件,按 CTRL+a,按 CTRL+i,完成。

但是对于 XML 文件该怎么做呢?与 Java 不同,对于 XML 文件,CTRL+a/CTRL+i 不仅可以转换制表符,而且还尝试“改进格式”,这会破坏一切:

初始代码:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans>
<bean id="webscript.helloworld.get"
class="com.example.HelloWorldWebScript"
parent="webscript">
</bean>
</beans>

在 CTRL+a/CTRL+i(或 CTRL+SHIFT+f)之后:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. The ASF licenses this file to
You under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<beans>
<bean id="webscript.helloworld.get" class="com.example.HelloWorldWebScript"
parent="webscript">
</bean>
</beans>

问题:对于 Eclipse 中的 XML 文件,如何将制表符转换为空格,而不进行其他更改?

最佳答案

你的方法是对的,但首先,你必须自定义 XML 格式:

  • 打开窗口 > 首选项 > XML > XML 文件 > 编辑器
  • 选中格式注释并取消选中连接行。 (这应该缩进注释并删除相邻的空格,从而保留现有的换行符。但如果您对结果感到不舒服,请取消选中格式注释。)
  • 选择使用空格缩进并设置缩进大小

现在您可以按[SHIFT][CTRL][F]格式化您的XML文件。

Eclipse XML Formatting preferences

关于xml - 将 XML 文件中的制表符更改为空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42711733/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com