Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将选项卡更改为XML文件中的空格_Xml_Eclipse - Fatal编程技术网

将选项卡更改为XML文件中的空格

将选项卡更改为XML文件中的空格,xml,eclipse,Xml,Eclipse,在已经创建了许多文件之后,我将Eclipse配置更改为。它有效:我写的新东西使用空格。但我昨天写的文件当然还有标签。我想将它们从制表符转换为空格 对于Java文件,这很简单:打开文件,按CTRL+a,按CTRL+i,完成 但是如何对XML文件执行?与Java不同,使用XML文件CTRL+a/CTRL+i不仅可以转换选项卡,还可以尝试“改进格式”,这会破坏一切: 初始代码: <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE bean

在已经创建了许多文件之后,我将Eclipse配置更改为。它有效:我写的新东西使用空格。但我昨天写的文件当然还有标签。我想将它们从制表符转换为空格

对于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)之后:



问题对于Eclipse中的XML文件,如何在没有其他更改的情况下将制表符转换为空格?

如果您是手动操作,并且不需要自动脚本,只需在XML文件中编写一个制表符,复制它,然后ctrl+f>替换,将制表符粘贴到“查找内容”和“替换为”中的空格中,然后将其全部替换即可。这是因为您不想用脚本替换它。

搜索
->
搜索…
(或Ctrl+H)->
文件搜索

选中正则表达式

\t
设置为包含以下文本的

*.xml
设置为
文件名模式

点击
Replace…
,设置
(根据需要放置空格)->
确定


完成了。享受

您的方法是正确的,但首先,您必须自定义XML格式:

  • 打开
    Window>Preferences>XML>XML文件>编辑器
  • 选中
    格式化注释
    并取消选中
    连接行
    。(这将缩进注释并删除相邻空格,从而保留现有的换行符。但是如果您对结果感到不舒服,请取消选中
    格式化注释
  • 选择
    使用空格缩进
    并设置
    缩进大小
现在,您可以通过按
[SHIFT][CTRL][F]
来格式化XML文件


现在无法检查,这是一篇旧文章,因此不确定这是否仍然有效,但还是一个更手动的解决方案@AxelH:not replice。询问如何更改设置,我已经这样做了。只有Ctrl+Shift+F答案,正如您所知,Ctrl+Shift+F会破坏所有格式设置(请尝试上面的示例代码)。请重新阅读我的问题:我已经将Eclipse设置为使用空格而不是制表符,并且我想要一个只固定空格而不进行任何其他格式设置的命令。我的错误,误读了您使用的快捷方式。我看到了两个解决方案,一个是脚本,另一个是在eclipse中创建一个新格式,它只会编辑选项卡,禁用其他所有内容。我无法进行测试,因为office没有不幸地使用eclipse,所以不确定是否可以禁用每个格式选项。示例中的问题是column length属性,设置一个巨大的值来修复它,这确实是一个选项。我仍然希望有一个更简单的捷径,但如果没有更好的捷径,我会接受这个。或者,你可以找到一个脚本,我的意思是应该有大量的SCRPT可以做到这一点,对于一个我认为并不难做的,它只需要通过PHP端上传和下载,至少我只知道如何通过PHP实现,哈哈,或者应该有使用的脚本我添加了一个屏幕截图,配置是否显示了您的意思?不幸的是,除了修复缩进之外,它还连接XML属性行,例如在我的示例中,
id
class
位于同一行。虽然我可以选中
将多个属性拆分为一行
,但在我的一些文件中,有许多短属性,我不希望这样。我希望Eclipse有一个与Java格式化程序类似的XML格式化程序:修复缩进而不做其他事情。无论如何,谢谢你,这可能是最接近我的梦想形成者!是的,我就是这个意思。是的,恐怕这是你能得到的最接近的了。Eclipse格式化程序都不是完美的!:-(
<?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>