在 Eclipse 中禁用 XML 验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7489510/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 14:57:57  来源:igfitidea点击:

Disable XML validation in Eclipse

xmleclipse

提问by Satish

My Eclipse validates XML files every time I save a file and it takes a while to validate them. The project is created using gwt-maven-plugin.

每次我保存文件时,我的 Eclipse 都会验证 XML 文件,并且验证它们需要一段时间。该项目是使用 gwt-maven-plugin 创建的。

The XML files are not under any Source folder build path in Eclipse, they are auto generated by SmartGWT under src/main/webapp/[GwtModule]>/sc

XML 文件不在 Eclipse 的任何 Source 文件夹构建路径下,它们是由 SmartGWT 在 src/main/webapp/[GwtModule]>/sc 下自动生成的

Also all these XML files are marked with the error "Content is not allowed in prolog" and every time I run the project I have to confirm that I want to run the project with errors though there are none (and everything works fine).

此外,所有这些 XML 文件都标有错误“序言中不允许使用内容”,每次我运行项目时,我都必须确认我想运行项目但没有错误(并且一切正常)。

I tried Suspending all Validators under Eclipse -> Window -> Preferences -> Validation but to no avail.

我尝试在 Eclipse -> Window -> Preferences -> Validation 下暂停所有验证器,但无济于事。

Any idea how I can stop Eclipse from annoying me every time?

知道如何阻止 Eclipse 每次都惹恼我吗?

回答by Mahmoud Saleh

You have two options:

您有两个选择:

  1. Configure Workspace Settings(disable the validation for the current workspace): Go to Window > Preferences > Validation and uncheck the manual and build for: XML Schema Validator, XML Validator

  2. Check enable project specific settings(disable the validation for this project): Right-click on the project, select Properties > Validation and uncheck the manual and build for: XML Schema Validator, XML Validator

  1. 配置工作区设置(禁用当前工作区的验证):转到窗口 > 首选项 > 验证并取消选中手册并构建:XML Schema Validator、XML Validator

  2. 检查启用项目特定设置(禁用此项目的验证):右键单击项目,选择属性 > 验证并取消选中手册并构建:XML Schema Validator、XML Validator

Right-clickon the project and select Validateto make the errors disappear.

右键单击项目并选择验证以使错误消失。

回答by kevinarpe

The other answers may work for you, but they did not cover my case. I wanted someXML to be validated, and others not. This image shows how to exclude certain folders (or files) for XML validation.

其他答案可能对您有用,但它们并未涵盖我的情况。我想要一些XML 被验证,而另一些则不需要。此图显示了如何排除某些文件夹(或文件)以进行 XML 验证。

Begin by right clicking the root of your Eclipse project. Select the last item: Properties...

首先右键单击 Eclipse 项目的根目录。选择最后一项:属性...

enter image description here

在此处输入图片说明

(If your browser scales this image very small, right click and open in a new window or tab.)

(如果您的浏览器将此图像缩放得非常小,请右键单击并在新窗口或选项卡中打开。)

  • Eclipse appears to be very sensitive if you click the **Browse File...* or **Browser Folder...* button. This dialog needs some work!
  • This was done using Eclipse 4.3 (Kepler).
  • 如果您单击 **Browse File...* 或 **Browser Folder...* 按钮,Eclipse 似乎非常敏感。这个对话框需要一些工作!
  • 这是使用 Eclipse 4.3 (Kepler) 完成的。

回答by Mark

Window > Preferences > Validation > uncheck XML Validator Manual and Build enter image description here

Window > Preferences > Validation > 取消选中 XML Validator Manual and Build 在此处输入图片说明

回答by Matthew Farwell

Ensure your encoding is correct for all of your files, this can sometimes happen if you have the encoding wrong for your file or the wrong encoding in your XML header.

确保您的所有文件的编码都是正确的,如果您的文件编码错误或 XML 标头中的编码错误,有时会发生这种情况。

So, if I have the following NewFile.xml:

所以,如果我有以下 NewFile.xml:

<?xml version="1.0" encoding="UTF-16"?>
<bar foo="ftheitroadé" />

And the eclipse encoding is UTF-8:

Eclipse 编码为 UTF-8:

Eclipse Encoding Resource

Eclipse 编码资源

The encoding of your file, the defined encoding in Eclipse (through Properties->Resource) and the declared encoding in the XML document all need to agree.

您的文件的编码、Eclipse 中定义的编码(通过 Properties->Resource)和 XML 文档中声明的编码都需要一致。

The validator is attempting to read the file, expecting <?xml ... but because the encoding is different from that expected, it's not finding it. Hence the error: Content is not allowed in prolog. The prolog is the bit before the <?xml declaration.

验证器正在尝试读取文件,期望 <?xml ... 但由于编码与预期不同,它没有找到它。因此出现错误:序言中不允许使用内容。序言是 <?xml 声明之前的位。

EDIT: Sorry, didn't realise that the .xml files were generated and actually contain javascript.

编辑:抱歉,没有意识到 .xml 文件已生成并且实际上包含 javascript。

When you suspend the validators, the error messages that you've generated don't go away. To get them to go away, you have to manually delete them.

当您暂停验证器时,您生成的错误消息不会消失。要让它们消失,您必须手动删除它们。

  1. Suspend the validators
  2. Click on the 'Content is not allowed in prolog' message, right click and delete. You can select multiple ones, or all of them.
  3. Do a Project->Clean. The messages should not come back.
  1. 暂停验证器
  2. 单击“序言中不允许内容”消息,右键单击并删除。您可以选择多个,也可以全部选择。
  3. 做一个项目->清理。消息不应返回。

I think that because you've suspended the validators, Eclipse doesn't realise it has to delete the old error messages which came from the validators.

我认为因为您暂停了验证器,Eclipse 没有意识到它必须删除来自验证器的旧错误消息。

回答by Fuzzy Analysis

In JBoss Developer 4.0 and above (Eclipse-based), this is a tad easier. Just right-click on your file or folder that contains xml-based files, choose "Exclude Validation", then click "Yes" to confirm. Then right-click the same files/folder again and click on "Validate", which will remove the errors with a confirmation.

在 JBoss Developer 4.0 及更高版本(基于 Eclipse)中,这更容易一些。只需右键单击包含基于 xml 文件的文件或文件夹,选择“排除验证”,然后单击“是”进行确认。然后再次右键单击相同的文件/文件夹并单击“验证”,这将通过确认删除错误。